Skip to content

Commit a442a08

Browse files
committed
Implement PDFNetworkStreamRangeRequestReader._onError, to handle range request errors with XMLHttpRequest (issue 9883)
Given that the Fetch API is normally being used now, these changes are probably less important now than they used to be. However, given that it's simple enough to implement this I figured why not just fix issue 9883 (better late than never I suppose).
1 parent 8ecc7d9 commit a442a08

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/display/network.js

+16
Original file line numberDiff line numberDiff line change
@@ -410,14 +410,18 @@ class PDFNetworkStreamFullRequestReader {
410410
class PDFNetworkStreamRangeRequestReader {
411411
constructor(manager, begin, end) {
412412
this._manager = manager;
413+
413414
const args = {
414415
onDone: this._onDone.bind(this),
416+
onError: this._onError.bind(this),
415417
onProgress: this._onProgress.bind(this),
416418
};
419+
this._url = manager.url;
417420
this._requestId = manager.requestRange(begin, end, args);
418421
this._requests = [];
419422
this._queuedChunk = null;
420423
this._done = false;
424+
this._storedError = undefined;
421425

422426
this.onProgress = null;
423427
this.onClosed = null;
@@ -443,6 +447,15 @@ class PDFNetworkStreamRangeRequestReader {
443447
this._close();
444448
}
445449

450+
_onError(status) {
451+
this._storedError = createResponseStatusError(status, this._url);
452+
for (const requestCapability of this._requests) {
453+
requestCapability.reject(this._storedError);
454+
}
455+
this._requests.length = 0;
456+
this._queuedChunk = null;
457+
}
458+
446459
_onProgress(evt) {
447460
if (!this.isStreamingSupported) {
448461
this.onProgress?.({ loaded: evt.loaded });
@@ -454,6 +467,9 @@ class PDFNetworkStreamRangeRequestReader {
454467
}
455468

456469
async read() {
470+
if (this._storedError) {
471+
throw this._storedError;
472+
}
457473
if (this._queuedChunk !== null) {
458474
const chunk = this._queuedChunk;
459475
this._queuedChunk = null;

0 commit comments

Comments
 (0)