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() {
document.addEventListener('unhandledRPCError', (event) => {
document.addEventListener('unhandledError', (event) => {
this.alertError(event.detail);
});

View file

@ -31,7 +31,7 @@ lbry.jsonrpc_call = function (connectionString, method, params, callback, errorC
if (errorCallback) {
errorCallback(response.error);
} else {
var errorEvent = new CustomEvent('unhandledRPCError', {
var errorEvent = new CustomEvent('unhandledError', {
detail: {
connectionString: connectionString,
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.send(JSON.stringify({
'jsonrpc': '2.0',