From 12af2f9431cf2bfb4e36806b83499010e0b16887 Mon Sep 17 00:00:00 2001 From: Bill Walker Date: Tue, 29 Jan 2013 10:13:28 -0800 Subject: [PATCH] fix for #2219, "provide a better error message when file= not found/accessible" summary: create a new Exception class for missing PDF's, use it in place of generic add new MissingPDFException to util.js handle MissingPDF in api.js handle MissingPDF in viewer.js, using new missing_file_error message add new missing_file_error to l10n/en-US/viewer.properties send MissingPDF from WorkerMessageHandler's loadDocument send MissingPDF from GetDocRequest handler --- l10n/en-US/viewer.properties | 1 + src/api.js | 4 ++++ src/util.js | 12 ++++++++++++ src/worker.js | 17 +++++++++++++++-- web/viewer.js | 11 +++++++++++ 5 files changed, 43 insertions(+), 2 deletions(-) diff --git a/l10n/en-US/viewer.properties b/l10n/en-US/viewer.properties index 8c86eed10..0d5ff76fe 100644 --- a/l10n/en-US/viewer.properties +++ b/l10n/en-US/viewer.properties @@ -111,6 +111,7 @@ page_scale_actual=Actual Size loading_error_indicator=Error loading_error=An error occurred while loading the PDF. invalid_file_error=Invalid or corrupted PDF file. +missing_file_error=Missing PDF file. # LOCALIZATION NOTE (text_annotation_type): This is used as a tooltip. # "{{type}}" will be replaced with an annotation type from a list defined in diff --git a/src/api.js b/src/api.js index 40dd52a25..2883d2ec5 100644 --- a/src/api.js +++ b/src/api.js @@ -547,6 +547,10 @@ var WorkerTransport = (function WorkerTransportClosure() { this.workerReadyPromise.reject(data.exception.name, data.exception); }, this); + messageHandler.on('MissingPDF', function transportMissingPDF(data) { + this.workerReadyPromise.reject(data.exception.message, data.exception); + }, this); + messageHandler.on('UnknownError', function transportUnknownError(data) { this.workerReadyPromise.reject(data.exception.message, data.exception); }, this); diff --git a/src/util.js b/src/util.js index 4f856b798..f30a42032 100644 --- a/src/util.js +++ b/src/util.js @@ -175,6 +175,18 @@ var InvalidPDFException = (function InvalidPDFExceptionClosure() { return InvalidPDFException; })(); +var MissingPDFException = (function MissingPDFExceptionClosure() { + function MissingPDFException(msg) { + this.name = 'MissingPDFException'; + this.message = msg; + } + + MissingPDFException.prototype = new Error(); + MissingPDFException.constructor = MissingPDFException; + + return MissingPDFException; +})(); + function bytesToString(bytes) { var str = ''; var length = bytes.length; diff --git a/src/worker.js b/src/worker.js index 47eb8b1da..fa53a0dde 100644 --- a/src/worker.js +++ b/src/worker.js @@ -130,6 +130,12 @@ var WorkerMessageHandler = { exception: e }); + return; + } else if (e instanceof MissingPDFException) { + handler.send('MissingPDF', { + exception: e + }); + return; } else { handler.send('UnknownError', { @@ -185,8 +191,15 @@ var WorkerMessageHandler = { }); }, error: function getPDFError(e) { - handler.send('DocError', 'Unexpected server response of ' + - e.target.status + '.'); + if (e.target.status == 404) { + handler.send('MissingPDF', { + exception: new MissingPDFException( + 'Missing PDF \"' + source.url + '\".')}); + } else { + handler.send('DocError', 'Unexpected server response (' + + e.target.status + ') while retrieving PDF \"' + + source.url + '\".'); + } }, headers: source.httpHeaders }, diff --git a/web/viewer.js b/web/viewer.js index 5c2b1f980..ab4b85ea1 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -1000,6 +1000,17 @@ var PDFView = { //#endif } + if (exception && exception.name === 'MissingPDFException') { + // special message for missing PDF's + var loadingErrorMessage = mozL10n.get('missing_file_error', null, + 'Missing PDF file.'); + +//#if B2G +// window.alert(loadingErrorMessage); +// return window.close(); +//#endif + } + var loadingIndicator = document.getElementById('loading'); loadingIndicator.textContent = mozL10n.get('loading_error_indicator', null, 'Error');