From 8fd28a91858d5a530a73773591a199c1091b74c1 Mon Sep 17 00:00:00 2001 From: Jakub Holy Date: Sun, 24 Mar 2013 17:58:01 +0100 Subject: [PATCH 1/2] Better error reporting for external Markdown files 1. Show an alert when loading the file throws an exception 2. Whenever the status isn't success (2xx) - upon exception or e.g. "file not found" - replace the section's content with information about the failure (instead of being silent about it and showing a blank slide). We need to inform the user something went wrong, not just be silent about it. An experienced developer, upon seing a blank slide, will likely check the javascript console - but the rest will profit from being told about the problem (and solution) explicitely. --- plugin/markdown/markdown.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/plugin/markdown/markdown.js b/plugin/markdown/markdown.js index b6b5a9b..11a6fc2 100644 --- a/plugin/markdown/markdown.js +++ b/plugin/markdown/markdown.js @@ -101,12 +101,21 @@ xhr.onreadystatechange = function () { if( xhr.readyState === 4 ) { - section.outerHTML = slidifyMarkdown( xhr.responseText, section.getAttribute('data-separator'), section.getAttribute('data-vertical') ); + if (xhr.status >= 200 && xhr.status < 300) { + section.outerHTML = slidifyMarkdown( xhr.responseText, section.getAttribute('data-separator'), section.getAttribute('data-vertical') ); + } else { + section.outerHTML = '
ERROR: The attempt to fetch ' + url + ' failed with the HTTP status ' + xhr.status + + '. Check your browser\'s JavaScript console for more details.
'; + } } }; xhr.open('GET', url, false); - xhr.send(); + try { + xhr.send(); + } catch (e) { + alert('Failed to get the Markdown file ' + url + '. Make sure that the presentation and the file are served by a HTTP server and the file can be found there. ' + e); + } } else if( section.getAttribute('data-separator') ) { From f6487dc312539bb011434c7a8f9a80bc5b238a7c Mon Sep 17 00:00:00 2001 From: Jakub Holy Date: Sun, 24 Mar 2013 23:30:50 +0100 Subject: [PATCH 2/2] More verbose error slide (HTTP necessary) --- plugin/markdown/markdown.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/plugin/markdown/markdown.js b/plugin/markdown/markdown.js index 11a6fc2..3e31203 100644 --- a/plugin/markdown/markdown.js +++ b/plugin/markdown/markdown.js @@ -26,11 +26,11 @@ return text; }; - + var twrap = function(el) { return ''; }; - + var slidifyMarkdown = function(markdown, separator, vertical) { separator = separator || '^\n---\n$'; @@ -105,7 +105,8 @@ section.outerHTML = slidifyMarkdown( xhr.responseText, section.getAttribute('data-separator'), section.getAttribute('data-vertical') ); } else { section.outerHTML = '
ERROR: The attempt to fetch ' + url + ' failed with the HTTP status ' + xhr.status + - '. Check your browser\'s JavaScript console for more details.
'; + '. Check your browser\'s JavaScript console for more details.' + + '

Remember that you need to serve the presentation HTML from a HTTP server and the Markdown file must be there too.

'; } } };