From 1f56451d56f94f75616fa0b701a69ec3b2e83271 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Mon, 30 Aug 2021 09:57:39 +0200 Subject: [PATCH] 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). --- src/display/network.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/display/network.js b/src/display/network.js index 145772c72..b199d9846 100644 --- a/src/display/network.js +++ b/src/display/network.js @@ -409,14 +409,18 @@ class PDFNetworkStreamFullRequestReader { class PDFNetworkStreamRangeRequestReader { constructor(manager, begin, end) { this._manager = manager; + const args = { onDone: this._onDone.bind(this), + onError: this._onError.bind(this), onProgress: this._onProgress.bind(this), }; + this._url = manager.url; this._requestId = manager.requestRange(begin, end, args); this._requests = []; this._queuedChunk = null; this._done = false; + this._storedError = undefined; this.onProgress = null; this.onClosed = null; @@ -442,6 +446,15 @@ class PDFNetworkStreamRangeRequestReader { this._close(); } + _onError(status) { + this._storedError = createResponseStatusError(status, this._url); + for (const requestCapability of this._requests) { + requestCapability.reject(this._storedError); + } + this._requests.length = 0; + this._queuedChunk = null; + } + _onProgress(evt) { if (!this.isStreamingSupported) { this.onProgress?.({ loaded: evt.loaded }); @@ -453,6 +466,9 @@ class PDFNetworkStreamRangeRequestReader { } async read() { + if (this._storedError) { + throw this._storedError; + } if (this._queuedChunk !== null) { const chunk = this._queuedChunk; this._queuedChunk = null;