1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-19 14:48:08 +02:00

[api-major] Replace MissingPDFException and UnexpectedResponseException with one exception

These old exceptions have a fair amount of overlap given how/where they are being used, which is likely because they were introduced at different points in time, hence we can shorten and simplify the code by replacing them with a more general `ResponseException` instead.

Besides an error message, the new `ResponseException` instances also include:
 - A numeric `status` field containing the server response status, similar to the old `UnexpectedResponseException`.

 - A boolean `missing` field, to allow easily detecting the situations where `MissingPDFException` was previously thrown.
This commit is contained in:
Jonas Jenwald 2024-12-28 14:20:48 +01:00
parent 7a57af12e1
commit 75cba72ca6
15 changed files with 65 additions and 92 deletions

View file

@ -50,12 +50,11 @@ import {
InvalidPDFException,
isDataScheme,
isPdfFile,
MissingPDFException,
PDFWorker,
ResponseException,
shadow,
stopEvent,
TouchManager,
UnexpectedResponseException,
version,
} from "pdfjs-lib";
import { AppOptions, OptionKind } from "./app_options.js";
@ -1108,10 +1107,10 @@ const PDFViewerApplication = {
let key = "pdfjs-loading-error";
if (reason instanceof InvalidPDFException) {
key = "pdfjs-invalid-file-error";
} else if (reason instanceof MissingPDFException) {
key = "pdfjs-missing-file-error";
} else if (reason instanceof UnexpectedResponseException) {
key = "pdfjs-unexpected-response-error";
} else if (reason instanceof ResponseException) {
key = reason.missing
? "pdfjs-missing-file-error"
: "pdfjs-unexpected-response-error";
}
return this._documentError(key, { message: reason.message }).then(
() => {