I use PDFJS to display PDFs. Most errors are catched properly by this fragment of viewer.js (file from the PDFJS package):
PDFJS.getDocument(parameters, pdfDataRangeTransport, passwordNeeded).then(
function getDocumentCallback(pdfDocument) {
self.load(pdfDocument, scale);
self.loading = false;
},
function getDocumentError(message, exception) {
But when PDF has 0 length an error :
Error: stream must have data
util.js (wiersz 62)
assertWellFormed@http://www.polishwords.com.pl/dev/pdfjs/src/util.js:124:5
init@http://www.polishwords.com.pl/dev/pdfjs/src/core.js:296:5
PDFDocument@http://www.polishwords.com.pl/dev/pdfjs/src/core.js:288:7
LocalPdfManager@http://www.polishwords.com.pl/dev/pdfjs/src/pdf_manager.js:75:21
onDone@http://www.polishwords.com.pl/dev/pdfjs/src/worker.js:212:24
NetworkManager_onStateChange@http://www.polishwords.com.pl/dev/pdfjs/src/network.js:190:1
util.js (wiersz 64)
Error: stream must have data
throw new Error(msg);
The fragment of the code throwing the error in util.js looks like this:
// Fatal errors that should trigger the fallback UI and halt execution by
// throwing an exception.
function error(msg) {
// If multiple arguments were passed, pass them all to the log function.
if (arguments.length > 1) {
var logArguments = ['Error:'];
logArguments.push.apply(logArguments, arguments);
log.apply(null, logArguments);
// Join the arguments into a single string for the lines below.
msg = [].join.call(arguments, ' ');
} else {
log('Error: ' + msg);
}
log(backtrace());
PDFJS.LogManager.notify('error', msg);
throw new Error(msg);
}
So my question is, how to properly handle 0 file size PDF error in PDF JS in viewer.js PDFView class?