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

Commit c50468f

Browse files
committed
Merge pull request #108 from whipsch/fix-playpen-errors
Improve playpen error handling
2 parents 0443e47 + 53b695a commit c50468f

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

_includes/editor.js

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,21 +84,31 @@
8484
// console.log("Sending", data);
8585
req.open('POST', "https://play.rust-lang.org/evaluate.json", true);
8686
req.onload = function(e) {
87+
var statusCode = false;
88+
var result = null;
89+
8790
if (req.readyState === 4 && req.status === 200) {
88-
var result = JSON.parse(req.response).result;
91+
result = JSON.parse(req.response);
8992

90-
// Need server support to get an accurate version of this.
91-
var statusCode = SUCCESS;
92-
if (result.indexOf("error:") !== -1) {
93+
// handle application errors from playpen
94+
if (typeof result['error'] === 'string') {
9395
statusCode = ERROR;
94-
} else if (result.indexOf("warning:") !== -1) {
95-
statusCode = WARNING;
96+
result = 'Playpen Error: ' + result['error'];
97+
} else if (typeof result['result'] === 'string') {
98+
statusCode = SUCCESS;
99+
result = result['result'];
100+
101+
// handle rustc errors/warnings
102+
// Need server support to get an accurate version of this.
103+
if (result.indexOf("error:") !== -1) {
104+
statusCode = ERROR;
105+
} else if (result.indexOf("warning:") !== -1) {
106+
statusCode = WARNING;
107+
}
96108
}
97-
98-
callback(statusCode, result);
99-
} else {
100-
callback(false, null);
101109
}
110+
111+
callback(statusCode, result);
102112
};
103113

104114
req.onerror = function(e) {

0 commit comments

Comments
 (0)