mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-21 15:48:06 +02:00
Attempt to improve the PDFDocument
error message for empty files (issue 5887)
Given that the error in question is surfaced on the API-side, this patch makes the following changes: - Updates the wording such that it'll hopefully be slightly easier for users to understand. - Changes the plain `Error` to an `InvalidPDFException` instead, since that should work better with the existing Error handling. - Adds a unit-test which loads an empty PDF document (and also improves a pre-existing `InvalidPDFException` message and its test-case).
This commit is contained in:
parent
a6db045789
commit
b00835f589
3 changed files with 24 additions and 7 deletions
|
@ -148,8 +148,10 @@ describe('api', function() {
|
|||
var loadingTask = getDocument(buildGetDocumentParams('bug1020226.pdf'));
|
||||
loadingTask.promise.then(function () {
|
||||
done.fail('shall fail loading');
|
||||
}).catch(function (error) {
|
||||
expect(error instanceof InvalidPDFException).toEqual(true);
|
||||
}).catch(function(reason) {
|
||||
expect(reason instanceof InvalidPDFException).toEqual(true);
|
||||
expect(reason.message).toEqual('Invalid PDF structure.');
|
||||
|
||||
loadingTask.destroy().then(done);
|
||||
});
|
||||
});
|
||||
|
@ -292,6 +294,20 @@ describe('api', function() {
|
|||
done();
|
||||
}).catch(done.fail);
|
||||
});
|
||||
|
||||
it('creates pdf doc from empty typed array', function(done) {
|
||||
const loadingTask = getDocument(new Uint8Array(0));
|
||||
|
||||
loadingTask.promise.then(function() {
|
||||
done.fail('shall not open empty file');
|
||||
}, function(reason) {
|
||||
expect(reason instanceof InvalidPDFException);
|
||||
expect(reason.message).toEqual(
|
||||
'The PDF file is empty, i.e. its size is zero bytes.');
|
||||
|
||||
loadingTask.destroy().then(done);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('PDFWorker', function() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue