diff --git a/es6.js b/es6.js index 060d7a9..4fe3959 100644 --- a/es6.js +++ b/es6.js @@ -20,7 +20,11 @@ define([ //Do not explicitly handle errors, those should be //visible via console output in the browser. if (xhr.readyState === 4) { - callback(xhr.responseText); + if (xhr.status === 200) { + callback(null, xhr.responseText); + } else { + callback(new Error(xhr.statusText)); + } } }; xhr.send(null); @@ -31,7 +35,11 @@ define([ //Using special require.nodeRequire, something added by r.js. var fs = require.nodeRequire('fs'); fetchText = function (path, callback) { - callback(fs.readFileSync(path, 'utf8')); + try { + callback(null, fs.readFileSync(path, 'utf8')); + } catch (error) { + callback(error); + } }; } @@ -80,7 +88,11 @@ return { options.sourceFileName = sourceFileName; options.sourceMap = config.isBuild ? false : 'inline'; - fetchText(url, function (text) { + fetchText(url, function (error, text) { + if (error) { + return onload.error(error); + } + var code; try { code = babel.transform(text, options).code;