Clean up code from SingleFile error handling fix

This commit is contained in:
Fletcher Hazlehurst 2020-09-28 11:48:53 -07:00
parent 1c5cefaffd
commit 37cdba6f40

View file

@ -575,8 +575,8 @@ Zotero.Utilities.Internal = {
const xhrRequest = new XMLHttpRequest(); const xhrRequest = new XMLHttpRequest();
xhrRequest.withCredentials = true; xhrRequest.withCredentials = true;
xhrRequest.responseType = "arraybuffer"; xhrRequest.responseType = "arraybuffer";
xhrRequest.onerror = (e) => { xhrRequest.onerror = () => {
let error = e.detail; let error = { error: `Request failed for ${url}` };
onDone(Components.utils.cloneInto(error, sandbox)); onDone(Components.utils.cloneInto(error, sandbox));
}; };
xhrRequest.onreadystatechange = () => { xhrRequest.onreadystatechange = () => {
@ -591,7 +591,7 @@ Zotero.Utilities.Internal = {
onDone(Components.utils.cloneInto(res, sandbox)); onDone(Components.utils.cloneInto(res, sandbox));
} }
else { else {
let error = 'Bad Status or Length'; let error = { error: 'Bad Status or Length' };
onDone(Components.utils.cloneInto(error, sandbox)); onDone(Components.utils.cloneInto(error, sandbox));
} }
} }
@ -615,13 +615,13 @@ Zotero.Utilities.Internal = {
catch (error) { catch (error) {
let response = await new Promise((resolve, reject) => { let response = await new Promise((resolve, reject) => {
coFetch(url, (response) => { coFetch(url, (response) => {
if (typeof response === 'object') { if (response.error) {
resolve(response);
}
else {
Zotero.debug("Error retrieving url: " + url); Zotero.debug("Error retrieving url: " + url);
Zotero.debug(response); Zotero.debug(response);
reject(new Error(response)); reject(new Error(response.error));
}
else {
resolve(response);
} }
}); });
}); });