Ignore fetch() errors, in PDFFetchStreamRangeReader, once the request has been aborted

Besides making general sense, as far as I can tell, this patch should also prevent *one* source of `Uncaught (in promise) ...` exceptions.
Unfortunately `reason instanceof AbortError` doesn't work here, since `AbortError` isn't actually defined in browsers; note how even the DOM specification contains an example using the `name` property: https://dom.spec.whatwg.org/#aborting-ongoing-activities

This patch prevents the following errors from being logged in the console, when the unit-tests are running:
 - Firefox: `Uncaught (in promise) DOMException: The operation was aborted.`
 - Chrome: `Uncaught (in promise) DOMException: The user aborted a request.`
This commit is contained in:
Jonas Jenwald 2020-07-28 17:03:50 +02:00
parent 403816040e
commit 1b720a4b23

View File

@ -243,13 +243,20 @@ class PDFFetchStreamRangeReader {
this._withCredentials,
this._abortController
)
).then(response => {
if (!validateResponseStatus(response.status)) {
throw createResponseStatusError(response.status, url);
}
this._readCapability.resolve();
this._reader = response.body.getReader();
});
)
.then(response => {
if (!validateResponseStatus(response.status)) {
throw createResponseStatusError(response.status, url);
}
this._readCapability.resolve();
this._reader = response.body.getReader();
})
.catch(reason => {
if (reason && reason.name === "AbortError") {
return;
}
throw reason;
});
this.onProgress = null;
}