Alert on AJAX connection failures
This commit is contained in:
parent
1173cb3f57
commit
80302786e1
2 changed files with 21 additions and 2 deletions
|
@ -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);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
21
js/lbry.js
21
js/lbry.js
|
@ -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',
|
||||||
|
|
Loading…
Reference in a new issue