Switch to callback based error handling for daemon requests

This commit is contained in:
Alex Liebowitz 2016-04-12 05:00:27 -04:00
parent dd4b7a621b
commit 1c896a4243

View file

@ -6,17 +6,17 @@ var lbry = {
}
};
lbry.call = function (method, params, callback, connectFailedCallback)
lbry.call = function (method, params, callback, errorCallback, connectFailedCallback)
{
var xhr = new XMLHttpRequest;
xhr.addEventListener('load', function() {
var response = JSON.parse(xhr.responseText);
if (response.error) {
throw new Error('Call to method ' + method + ' failed with message: ' + response.error);
}
if (callback) {
if (errorCallback) {
errorCallback(response.error);
}
} else if (callback) {
callback(response.result);
}
});
@ -64,7 +64,7 @@ lbry.daemonRunningStatus = function (callback) {
// Returns true/false whether the daemon is running (i.e. fully conncected to the network),
// or null if the AJAX connection to the daemon fails.
lbry.call('is_running', {}, callback, function () {
lbry.call('is_running', {}, callback, null, function () {
callback(null);
});
};