check for response.error to fix not handling error responses

This commit is contained in:
Sean Yesmunt 2020-03-13 15:54:44 -04:00
parent f9284b6e1a
commit d4d150bb39

View file

@ -12,7 +12,7 @@ import { doUpdateUploadProgress } from 'lbryinc';
// to perform calling methods at arbitrary urls // to perform calling methods at arbitrary urls
// and pass form file fields // and pass form file fields
export default function apiPublishCallViaWeb( export default function apiPublishCallViaWeb(
apiCall: (any) => void, apiCall: any => void,
connectionString: string, connectionString: string,
token: string, token: string,
method: string, method: string,
@ -72,11 +72,11 @@ export default function apiPublishCallViaWeb(
return makeRequest(connectionString, 'POST', token, body, params) return makeRequest(connectionString, 'POST', token, body, params)
.then(xhr => { .then(xhr => {
let error; let error;
if (xhr) { if (xhr && xhr.response) {
if (xhr.response && xhr.status >= 200 && xhr.status < 300) { if (xhr.status >= 200 && xhr.status < 300 && !xhr.response.error) {
return resolve(xhr.response.result); return resolve(xhr.response.result);
} else if (xhr.statusText) { } else if (xhr.response.error) {
error = new Error(xhr.statusText); error = new Error(xhr.response.error.message);
} else { } else {
error = new Error(__('Upload likely timed out. Try a smaller file while we work on this.')); error = new Error(__('Upload likely timed out. Try a smaller file while we work on this.'));
} }