mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-20 15:18: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:
parent
7a57af12e1
commit
75cba72ca6
15 changed files with 65 additions and 92 deletions
11
web/app.js
11
web/app.js
|
@ -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(
|
||||
() => {
|
||||
|
|
|
@ -442,6 +442,7 @@ const defaultOptions = {
|
|||
: "../web/wasm/",
|
||||
kind: OptionKind.API,
|
||||
},
|
||||
|
||||
workerPort: {
|
||||
/** @type {Object} */
|
||||
value: null,
|
||||
|
|
|
@ -37,7 +37,6 @@ const {
|
|||
InvalidPDFException,
|
||||
isDataScheme,
|
||||
isPdfFile,
|
||||
MissingPDFException,
|
||||
noContextMenu,
|
||||
normalizeUnicode,
|
||||
OPS,
|
||||
|
@ -49,12 +48,12 @@ const {
|
|||
PermissionFlag,
|
||||
PixelsPerInch,
|
||||
RenderingCancelledException,
|
||||
ResponseException,
|
||||
setLayerDimensions,
|
||||
shadow,
|
||||
stopEvent,
|
||||
TextLayer,
|
||||
TouchManager,
|
||||
UnexpectedResponseException,
|
||||
Util,
|
||||
VerbosityLevel,
|
||||
version,
|
||||
|
@ -85,7 +84,6 @@ export {
|
|||
InvalidPDFException,
|
||||
isDataScheme,
|
||||
isPdfFile,
|
||||
MissingPDFException,
|
||||
noContextMenu,
|
||||
normalizeUnicode,
|
||||
OPS,
|
||||
|
@ -97,12 +95,12 @@ export {
|
|||
PermissionFlag,
|
||||
PixelsPerInch,
|
||||
RenderingCancelledException,
|
||||
ResponseException,
|
||||
setLayerDimensions,
|
||||
shadow,
|
||||
stopEvent,
|
||||
TextLayer,
|
||||
TouchManager,
|
||||
UnexpectedResponseException,
|
||||
Util,
|
||||
VerbosityLevel,
|
||||
version,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue