Skip to content

Commit

Permalink
Show a redbox when scripts fail to load
Browse files Browse the repository at this point in the history
Reviewed By: yungsters

Differential Revision: D3670186

fbshipit-source-id: 1c61b69c74a8f7cc255aa6d7afcdb117205922eb
  • Loading branch information
ayc1 authored and Facebook Github Bot 3 committed Sep 7, 2016
1 parent e22abd9 commit bbd1e45
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import com.facebook.common.logging.FLog;
import com.facebook.infer.annotation.Assertions;
import com.facebook.react.common.JavascriptException;

import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonGenerator;
Expand Down Expand Up @@ -212,6 +213,10 @@ public void onMessage(ResponseBody response) throws IOException {
} else if ("result".equals(field)) {
parser.nextToken();
result = parser.getText();
} else if ("error".equals(field)) {
parser.nextToken();
String error = parser.getText();
abort(error, new JavascriptException(error));
}
}
if (replyID != null) {
Expand Down
13 changes: 9 additions & 4 deletions local-cli/server/util/debuggerWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,21 @@ var messageHandlers = {
for (var key in message.inject) {
self[key] = JSON.parse(message.inject[key]);
}
importScripts(message.url);
sendReply();
let error;
try {
importScripts(message.url);
} catch (err) {
error = JSON.stringify(err);
}
sendReply(null /* result */, error);
}
};

onmessage = function(message) {
var object = message.data;

var sendReply = function(result) {
postMessage({replyID: object.id, result: result});
var sendReply = function(result, error) {
postMessage({replyID: object.id, result: result, error: error});
};

var handler = messageHandlers[object.method];
Expand Down

0 comments on commit bbd1e45

Please sign in to comment.