1
0
Fork 0

Gracefully handle http errors

This commit is contained in:
Gregory Eremin 2016-01-10 19:35:22 +03:00
parent ef276ed577
commit 660f7b32dd
2 changed files with 11 additions and 6 deletions

View File

@ -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 {

View File

@ -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);
}