1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-21 15:48:06 +02:00

[api-minor] Reject the RenderTask with an actual Error, instead of just a string, when rendering is cancelled

This patch gets rid of the only case in the code-base where we're throwing a plain `string`, rather than an `Error`, which besides better/more consistent error handling also allows us to enable the [`no-throw-literal`](http://eslint.org/docs/rules/no-throw-literal) ESLint rule.
This commit is contained in:
Jonas Jenwald 2017-03-13 13:32:23 +01:00
parent 6d672c4ba6
commit d37d271afa
7 changed files with 66 additions and 8 deletions

View file

@ -418,7 +418,9 @@ var PDFPageView = (function PDFPageViewClosure() {
self.paintTask = null;
}
if (error === 'cancelled') {
if (((typeof PDFJSDev === 'undefined' ||
!PDFJSDev.test('PDFJS_NEXT')) && error === 'cancelled') ||
error instanceof pdfjsLib.RenderingCancelledException) {
self.error = null;
return Promise.resolve(undefined);
}
@ -625,7 +627,13 @@ var PDFPageView = (function PDFPageViewClosure() {
var cancelled = false;
var ensureNotCancelled = function () {
if (cancelled) {
throw 'cancelled';
if ((typeof PDFJSDev !== 'undefined' &&
PDFJSDev.test('PDFJS_NEXT')) || pdfjsLib.PDFJS.pdfjsNext) {
throw new pdfjsLib.RenderingCancelledException(
'Rendering cancelled, page ' + self.id, 'svg');
} else {
throw 'cancelled'; // eslint-disable-line no-throw-literal
}
}
};