mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-09 09:45:42 +02:00
Re-factor sending of various Exceptions from the worker to the API
As can be seen in the API, there's a number of document loading Exception handlers which are both really simple and highly similar. Hence these are changed such that all the relevant Exceptions are sent via *one* message instead. Furthermore, the patch also avoids unnecessarily re-creating `UnknownErrorException`s at the worker side and removes an unnecessary `bind` call.
This commit is contained in:
parent
11f3851a97
commit
df0e1edab5
2 changed files with 40 additions and 40 deletions
|
@ -2001,6 +2001,32 @@ class WorkerTransport {
|
|||
loadingTask._capability.resolve(new PDFDocumentProxy(pdfInfo, this));
|
||||
});
|
||||
|
||||
messageHandler.on('DocException', function(ex) {
|
||||
let reason;
|
||||
switch (ex.name) {
|
||||
case 'PasswordException':
|
||||
reason = new PasswordException(ex.message, ex.code);
|
||||
break;
|
||||
case 'InvalidPDFException':
|
||||
reason = new InvalidPDFException(ex.message);
|
||||
break;
|
||||
case 'MissingPDFException':
|
||||
reason = new MissingPDFException(ex.message);
|
||||
break;
|
||||
case 'UnexpectedResponseException':
|
||||
reason = new UnexpectedResponseException(ex.message, ex.status);
|
||||
break;
|
||||
case 'UnknownErrorException':
|
||||
reason = new UnknownErrorException(ex.message, ex.details);
|
||||
break;
|
||||
}
|
||||
if (typeof PDFJSDev === 'undefined' ||
|
||||
PDFJSDev.test('!PRODUCTION || TESTING')) {
|
||||
assert(reason instanceof Error, 'DocException: expected an Error.');
|
||||
}
|
||||
loadingTask._capability.reject(reason);
|
||||
});
|
||||
|
||||
messageHandler.on('PasswordRequest', (exception) => {
|
||||
this._passwordCapability = createPromiseCapability();
|
||||
|
||||
|
@ -2022,31 +2048,6 @@ class WorkerTransport {
|
|||
return this._passwordCapability.promise;
|
||||
});
|
||||
|
||||
messageHandler.on('PasswordException', function(exception) {
|
||||
loadingTask._capability.reject(
|
||||
new PasswordException(exception.message, exception.code));
|
||||
});
|
||||
|
||||
messageHandler.on('InvalidPDF', function(exception) {
|
||||
loadingTask._capability.reject(
|
||||
new InvalidPDFException(exception.message));
|
||||
});
|
||||
|
||||
messageHandler.on('MissingPDF', function(exception) {
|
||||
loadingTask._capability.reject(
|
||||
new MissingPDFException(exception.message));
|
||||
});
|
||||
|
||||
messageHandler.on('UnexpectedResponse', function(exception) {
|
||||
loadingTask._capability.reject(
|
||||
new UnexpectedResponseException(exception.message, exception.status));
|
||||
});
|
||||
|
||||
messageHandler.on('UnknownError', function(exception) {
|
||||
loadingTask._capability.reject(
|
||||
new UnknownErrorException(exception.message, exception.details));
|
||||
});
|
||||
|
||||
messageHandler.on('DataLoaded', (data) => {
|
||||
// For consistency: Ensure that progress is always reported when the
|
||||
// entire PDF file has been loaded, regardless of how it was fetched.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue