Commit a591fd20 authored by Alex Beregszaszi's avatar Alex Beregszaszi

Move HTTP (and Github API) error handling to app from compiler.

Also introduces finer error reporting why the import failed (404, 300, etc.)
parent 7a215cf4
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
var $ = require('jquery'); var $ = require('jquery');
var semver = require('semver'); var semver = require('semver');
var Base64 = require('js-base64').Base64;
var utils = require('./app/utils'); var utils = require('./app/utils');
var QueryParams = require('./app/query-params'); var QueryParams = require('./app/query-params');
...@@ -403,7 +404,17 @@ var run = function () { ...@@ -403,7 +404,17 @@ var run = function () {
function handleGithubCall (root, path, cb) { function handleGithubCall (root, path, cb) {
$('#output').append($('<div/>').append($('<pre/>').text('Loading github.com/' + root + '/' + path + ' ...'))); $('#output').append($('<div/>').append($('<pre/>').text('Loading github.com/' + root + '/' + path + ' ...')));
return $.getJSON('https://api.github.com/repos/' + root + '/contents/' + path, cb); return $.getJSON('https://api.github.com/repos/' + root + '/contents/' + path)
.done(function (data) {
if ('content' in data) {
cb(null, Base64.decode(data.content));
} else {
cb('Content not received');
}
})
.fail(function (xhr, text, err) {
cb(err);
});
} }
var executionContext = new ExecutionContext(); var executionContext = new ExecutionContext();
......
...@@ -3,8 +3,6 @@ var solc = require('solc/wrapper'); ...@@ -3,8 +3,6 @@ var solc = require('solc/wrapper');
var webworkify = require('webworkify'); var webworkify = require('webworkify');
var utils = require('./utils'); var utils = require('./utils');
var Base64 = require('js-base64').Base64;
var EventManager = require('../lib/eventManager'); var EventManager = require('../lib/eventManager');
/* /*
...@@ -237,17 +235,16 @@ function Compiler (editor, handleGithubCall) { ...@@ -237,17 +235,16 @@ function Compiler (editor, handleGithubCall) {
files[m] = cachedRemoteFiles[m]; files[m] = cachedRemoteFiles[m];
reloop = true; reloop = true;
} else if ((githubMatch = /^(https?:\/\/)?(www.)?github.com\/([^\/]*\/[^\/]*)\/(.*)/.exec(m))) { } else if ((githubMatch = /^(https?:\/\/)?(www.)?github.com\/([^\/]*\/[^\/]*)\/(.*)/.exec(m))) {
handleGithubCall(githubMatch[3], githubMatch[4], function (result) { handleGithubCall(githubMatch[3], githubMatch[4], function (err, content) {
if ('content' in result) { if (err) {
var content = Base64.decode(result.content); cb(null, 'Unable to import "' + m + '": ' + err);
cachedRemoteFiles[m] = content; return;
files[m] = content;
gatherImports(files, importHints, cb);
} else {
cb(null, 'Unable to import "' + m + '"');
} }
}).fail(function () {
cb(null, 'Unable to import "' + m + '"'); cachedRemoteFiles[m] = content;
files[m] = content;
gatherImports(files, importHints, cb);
}); });
return; return;
} else if (/^[^:]*:\/\//.exec(m)) { } else if (/^[^:]*:\/\//.exec(m)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment