diff --git a/js/app.js b/js/app.js index 35e1e8edd..9b7bad5a1 100644 --- a/js/app.js +++ b/js/app.js @@ -38,7 +38,7 @@ var App = React.createClass({ }); }, componentWillMount: function() { - document.addEventListener('unhandledRPCError', (event) => { + document.addEventListener('unhandledError', (event) => { this.alertError(event.detail); }); diff --git a/js/lbry.js b/js/lbry.js index d64ca1b3f..e39980e82 100644 --- a/js/lbry.js +++ b/js/lbry.js @@ -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',