Skip to content
This repository was archived by the owner on Sep 30, 2020. It is now read-only.

Improve playpen error handling #108

Merged
merged 1 commit into from
Apr 11, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions _includes/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,21 +84,31 @@
// console.log("Sending", data);
req.open('POST', "https://play.rust-lang.org/evaluate.json", true);
req.onload = function(e) {
var statusCode = false;
var result = null;

if (req.readyState === 4 && req.status === 200) {
var result = JSON.parse(req.response).result;
result = JSON.parse(req.response);

// Need server support to get an accurate version of this.
var statusCode = SUCCESS;
if (result.indexOf("error:") !== -1) {
// handle application errors from playpen
if (typeof result['error'] === 'string') {
statusCode = ERROR;
} else if (result.indexOf("warning:") !== -1) {
statusCode = WARNING;
result = 'Playpen Error: ' + result['error'];
} else if (typeof result['result'] === 'string') {
statusCode = SUCCESS;
result = result['result'];

// handle rustc errors/warnings
// Need server support to get an accurate version of this.
if (result.indexOf("error:") !== -1) {
statusCode = ERROR;
} else if (result.indexOf("warning:") !== -1) {
statusCode = WARNING;
}
}

callback(statusCode, result);
} else {
callback(false, null);
}

callback(statusCode, result);
};

req.onerror = function(e) {
Expand Down