Gracefully handle http errors
This commit is contained in:
parent
ef276ed577
commit
660f7b32dd
|
@ -9,6 +9,12 @@ var Dashboard = React.createClass({
|
|||
|
||||
reload: function() {
|
||||
getURL("http://127.0.0.1:6464/stats.json", {}, function(resp) {
|
||||
if (resp.error !== undefined) {
|
||||
console.log("Stats server is offline");
|
||||
setTimeout(this.reload, 3000);
|
||||
return
|
||||
}
|
||||
|
||||
var newState = {};
|
||||
var decode = function(point) {
|
||||
return {
|
||||
|
|
|
@ -31,7 +31,6 @@ function getURL(url, params, callback) {
|
|||
}
|
||||
|
||||
var xhr = getXHR();
|
||||
xhr.open('GET', url, true);
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.readyState === 4) {
|
||||
if(xhr.status === 200) {
|
||||
|
@ -39,10 +38,10 @@ function getURL(url, params, callback) {
|
|||
}
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
xhr.send(null);
|
||||
} catch (e) {
|
||||
xhr.onerror = function(e) {
|
||||
callback({error: e});
|
||||
}
|
||||
};
|
||||
|
||||
xhr.open('GET', url, true);
|
||||
xhr.send(null);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue