Merge pull request #11261 from Snuffleupagus/DocException
Re-factor sending of various Exceptions from the worker to the API
This commit is contained in:
commit
3c23ac212e
@ -270,30 +270,29 @@ var WorkerMessageHandler = {
|
|||||||
handler.send('GetDoc', { pdfInfo: doc, });
|
handler.send('GetDoc', { pdfInfo: doc, });
|
||||||
}
|
}
|
||||||
|
|
||||||
function onFailure(e) {
|
function onFailure(ex) {
|
||||||
ensureNotTerminated();
|
ensureNotTerminated();
|
||||||
|
|
||||||
if (e instanceof PasswordException) {
|
if (ex instanceof PasswordException) {
|
||||||
var task = new WorkerTask('PasswordException: response ' + e.code);
|
var task = new WorkerTask(`PasswordException: response ${ex.code}`);
|
||||||
startWorkerTask(task);
|
startWorkerTask(task);
|
||||||
|
|
||||||
handler.sendWithPromise('PasswordRequest', e).then(function (data) {
|
handler.sendWithPromise('PasswordRequest', ex).then(function(data) {
|
||||||
finishWorkerTask(task);
|
finishWorkerTask(task);
|
||||||
pdfManager.updatePassword(data.password);
|
pdfManager.updatePassword(data.password);
|
||||||
pdfManagerReady();
|
pdfManagerReady();
|
||||||
}).catch(function (boundException) {
|
}).catch(function() {
|
||||||
finishWorkerTask(task);
|
finishWorkerTask(task);
|
||||||
handler.send('PasswordException', boundException);
|
handler.send('DocException', ex);
|
||||||
}.bind(null, e));
|
});
|
||||||
} else if (e instanceof InvalidPDFException) {
|
} else if (ex instanceof InvalidPDFException ||
|
||||||
handler.send('InvalidPDF', e);
|
ex instanceof MissingPDFException ||
|
||||||
} else if (e instanceof MissingPDFException) {
|
ex instanceof UnexpectedResponseException ||
|
||||||
handler.send('MissingPDF', e);
|
ex instanceof UnknownErrorException) {
|
||||||
} else if (e instanceof UnexpectedResponseException) {
|
handler.send('DocException', ex);
|
||||||
handler.send('UnexpectedResponse', e);
|
|
||||||
} else {
|
} else {
|
||||||
handler.send('UnknownError',
|
handler.send('DocException',
|
||||||
new UnknownErrorException(e.message, e.toString()));
|
new UnknownErrorException(ex.message, ex.toString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2001,6 +2001,32 @@ class WorkerTransport {
|
|||||||
loadingTask._capability.resolve(new PDFDocumentProxy(pdfInfo, this));
|
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) => {
|
messageHandler.on('PasswordRequest', (exception) => {
|
||||||
this._passwordCapability = createPromiseCapability();
|
this._passwordCapability = createPromiseCapability();
|
||||||
|
|
||||||
@ -2022,31 +2048,6 @@ class WorkerTransport {
|
|||||||
return this._passwordCapability.promise;
|
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) => {
|
messageHandler.on('DataLoaded', (data) => {
|
||||||
// For consistency: Ensure that progress is always reported when the
|
// For consistency: Ensure that progress is always reported when the
|
||||||
// entire PDF file has been loaded, regardless of how it was fetched.
|
// entire PDF file has been loaded, regardless of how it was fetched.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user