Formatting cleanup, no functional change

Reducing diffs in the next commit.
This commit is contained in:
infinite-persistence 2022-03-18 16:42:10 +08:00 committed by Thomas Zarebczan
parent f0ef92614d
commit ce46170b39

View file

@ -177,19 +177,18 @@ const Lbry = {
}), }),
}; };
function checkAndParse(response) { function checkAndParse(response: Response) {
if (response.status >= 200 && response.status < 300) { if (response.status >= 200 && response.status < 300) {
return response.json(); return response.json();
} }
return response.json().then((json) => { return response.json().then((json) => {
let error;
if (json.error) { if (json.error) {
const errorMessage = typeof json.error === 'object' ? json.error.message : json.error; const errorMessage = typeof json.error === 'object' ? json.error.message : json.error;
error = new Error(errorMessage); return Promise.reject(new Error(errorMessage));
} else { } else {
error = new Error('Protocol error with unknown response signature'); return Promise.reject(new Error('Protocol error with unknown response signature'));
} }
return Promise.reject(error);
}); });
} }
@ -217,15 +216,12 @@ export function apiCall(method: string, params: ?{}, resolve: Function, reject:
const connectionString = Lbry.methodsUsingAlternateConnectionString.includes(method) const connectionString = Lbry.methodsUsingAlternateConnectionString.includes(method)
? Lbry.alternateConnectionString ? Lbry.alternateConnectionString
: Lbry.daemonConnectionString; : Lbry.daemonConnectionString;
return fetch(connectionString + '?m=' + method, options) return fetch(connectionString + '?m=' + method, options)
.then(checkAndParse) .then(checkAndParse)
.then((response) => { .then((response) => {
const error = response.error || (response.result && response.result.error); const error = response.error || (response.result && response.result.error);
return error ? reject(error) : resolve(response.result);
if (error) {
return reject(error);
}
return resolve(response.result);
}) })
.catch(reject); .catch(reject);
} }