Make the onError callback required in NetworkManager
This helps ensure that loading errors are always handled correctly, and note that both `PDFNetworkStreamFullRequestReader` and `PDFNetworkStreamRangeRequestReader` already provided such a callback.
This commit is contained in:
parent
2661d0623b
commit
eff8ede33e
@ -85,11 +85,10 @@ class NetworkManager {
|
|||||||
}
|
}
|
||||||
xhr.responseType = "arraybuffer";
|
xhr.responseType = "arraybuffer";
|
||||||
|
|
||||||
if (args.onError) {
|
assert(args.onError, "Expected `onError` callback to be provided.");
|
||||||
xhr.onerror = function (evt) {
|
xhr.onerror = () => {
|
||||||
args.onError(xhr.status);
|
args.onError(xhr.status);
|
||||||
};
|
};
|
||||||
}
|
|
||||||
xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
|
xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
|
||||||
xhr.onprogress = this.onProgress.bind(this, xhrId);
|
xhr.onprogress = this.onProgress.bind(this, xhrId);
|
||||||
|
|
||||||
@ -137,7 +136,7 @@ class NetworkManager {
|
|||||||
|
|
||||||
// Success status == 0 can be on ftp, file and other protocols.
|
// Success status == 0 can be on ftp, file and other protocols.
|
||||||
if (xhr.status === 0 && this.isHttp) {
|
if (xhr.status === 0 && this.isHttp) {
|
||||||
pendingRequest.onError?.(xhr.status);
|
pendingRequest.onError(xhr.status);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const xhrStatus = xhr.status || OK_RESPONSE;
|
const xhrStatus = xhr.status || OK_RESPONSE;
|
||||||
@ -153,7 +152,7 @@ class NetworkManager {
|
|||||||
!ok_response_on_range_request &&
|
!ok_response_on_range_request &&
|
||||||
xhrStatus !== pendingRequest.expectedStatus
|
xhrStatus !== pendingRequest.expectedStatus
|
||||||
) {
|
) {
|
||||||
pendingRequest.onError?.(xhr.status);
|
pendingRequest.onError(xhr.status);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,7 +167,7 @@ class NetworkManager {
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
warn(`Missing or invalid "Content-Range" header.`);
|
warn(`Missing or invalid "Content-Range" header.`);
|
||||||
pendingRequest.onError?.(0);
|
pendingRequest.onError(0);
|
||||||
}
|
}
|
||||||
} else if (chunk) {
|
} else if (chunk) {
|
||||||
pendingRequest.onDone({
|
pendingRequest.onDone({
|
||||||
@ -176,7 +175,7 @@ class NetworkManager {
|
|||||||
chunk,
|
chunk,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
pendingRequest.onError?.(xhr.status);
|
pendingRequest.onError(xhr.status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user