mirror of
https://github.com/LBRYFoundation/lbry-desktop.git
synced 2025-09-04 04:45:11 +00:00
Improve lbry.io API code
- Send as form data - Handle errors better
This commit is contained in:
parent
c374a59af8
commit
8299e229fd
1 changed files with 8 additions and 4 deletions
|
@ -57,18 +57,17 @@ lbryio.call = function(resource, action, params, method='get') {
|
||||||
console.log('loaded');
|
console.log('loaded');
|
||||||
const response = JSON.parse(xhr.responseText);
|
const response = JSON.parse(xhr.responseText);
|
||||||
|
|
||||||
if (response.error) {
|
if (!response.success) {
|
||||||
if (reject) {
|
if (reject) {
|
||||||
reject(new Error(response.error));
|
reject(new Error(response.error));
|
||||||
} else {
|
} else {
|
||||||
document.dispatchEvent(new CustomEvent('unhandledError', {
|
document.dispatchEvent(new CustomEvent('unhandledError', {
|
||||||
detail: {
|
detail: {
|
||||||
connectionString: connectionString,
|
connectionString: connectionString,
|
||||||
method: method,
|
method: action,
|
||||||
params: params,
|
params: params,
|
||||||
code: response.error.code,
|
|
||||||
message: response.error.message,
|
message: response.error.message,
|
||||||
data: response.error.data,
|
... response.error.data ? {data: response.error.data} : {},
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
@ -79,6 +78,11 @@ lbryio.call = function(resource, action, params, method='get') {
|
||||||
|
|
||||||
console.log('about to call xhr.open');
|
console.log('about to call xhr.open');
|
||||||
xhr.open(method, CONNECTION_STRING + resource + '/' + action, true);
|
xhr.open(method, CONNECTION_STRING + resource + '/' + action, true);
|
||||||
|
|
||||||
|
if (method == 'post') {
|
||||||
|
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
|
||||||
|
}
|
||||||
|
|
||||||
xhr.send(querystring.stringify(params));
|
xhr.send(querystring.stringify(params));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue