Alert on AJAX connection failures

This commit is contained in:
Alex Liebowitz 2016-10-22 05:22:44 -04:00 committed by Alex Work
parent 1173cb3f57
commit 80302786e1
2 changed files with 21 additions and 2 deletions

View file

@ -38,7 +38,7 @@ var App = React.createClass({
}); });
}, },
componentWillMount: function() { componentWillMount: function() {
document.addEventListener('unhandledRPCError', (event) => { document.addEventListener('unhandledError', (event) => {
this.alertError(event.detail); this.alertError(event.detail);
}); });

View file

@ -31,7 +31,7 @@ lbry.jsonrpc_call = function (connectionString, method, params, callback, errorC
if (errorCallback) { if (errorCallback) {
errorCallback(response.error); errorCallback(response.error);
} else { } else {
var errorEvent = new CustomEvent('unhandledRPCError', { var errorEvent = new CustomEvent('unhandledError', {
detail: { detail: {
connectionString: connectionString, connectionString: connectionString,
method: method, method: method,
@ -48,6 +48,25 @@ lbry.jsonrpc_call = function (connectionString, method, params, callback, errorC
} }
}); });
if (connectFailedCallback) {
xhr.addEventListener('error', function (event) {
connectFailedCallback(event);
});
} else {
xhr.addEventListener('error', function (event) {
var errorEvent = new CustomEvent('unhandledError', {
detail: {
connectionString: connectionString,
method: method,
params: params,
code: xhr.status,
message: 'Connection to API server failed'
}
});
document.dispatchEvent(errorEvent);
});
}
xhr.open('POST', connectionString, true); xhr.open('POST', connectionString, true);
xhr.send(JSON.stringify({ xhr.send(JSON.stringify({
'jsonrpc': '2.0', 'jsonrpc': '2.0',