[Pkg-javascript-commits] [pdf.js] 71/204: Add |UnexpectedResponseException| to fix the exception handling when file loading fails because the server responds with a non 404 status message

David Prévot taffit at moszumanska.debian.org
Sat Oct 25 18:50:33 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository pdf.js.

commit ed5fc43510443ab3e25cba695284cba3adb493cd
Author: Jonas Jenwald <jonas.jenwald at gmail.com>
Date:   Sat Sep 13 16:47:16 2014 +0200

    Add |UnexpectedResponseException| to fix the exception handling when file loading fails because the server responds with a non 404 status message
---
 l10n/en-US/viewer.properties |  1 +
 src/core/worker.js           | 24 ++++++++++++++----------
 src/display/api.js           | 14 ++++++++------
 src/shared/util.js           | 15 +++++++++++++++
 web/viewer.js                | 13 ++++++-------
 5 files changed, 44 insertions(+), 23 deletions(-)

diff --git a/l10n/en-US/viewer.properties b/l10n/en-US/viewer.properties
index dadfe41..c52020c 100644
--- a/l10n/en-US/viewer.properties
+++ b/l10n/en-US/viewer.properties
@@ -146,6 +146,7 @@ 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.
+unexpected_response_error=Unexpected server response.
 
 # LOCALIZATION NOTE (text_annotation_type.alt): This is used as a tooltip.
 # "{{type}}" will be replaced with an annotation type from a list defined in
diff --git a/src/core/worker.js b/src/core/worker.js
index 1e2450d..7dca8f0 100644
--- a/src/core/worker.js
+++ b/src/core/worker.js
@@ -14,11 +14,11 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/* globals error, globalScope, InvalidPDFException, info,
-           MissingPDFException, PasswordException, PDFJS, Promise,
-           UnknownErrorException, NetworkManager, LocalPdfManager,
-           NetworkPdfManager, XRefParseException, createPromiseCapability,
-           isInt, PasswordResponses, MessageHandler, Ref, RANGE_CHUNK_SIZE */
+/* globals PDFJS, createPromiseCapability, LocalPdfManager, NetworkPdfManager,
+           NetworkManager, isInt, RANGE_CHUNK_SIZE, MissingPDFException,
+           UnexpectedResponseException, PasswordException, Promise,
+           PasswordResponses, InvalidPDFException, UnknownErrorException,
+           XRefParseException, Ref, info, globalScope, error, MessageHandler */
 
 'use strict';
 
@@ -141,14 +141,16 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
         },
 
         onError: function onError(status) {
+          var exception;
           if (status === 404) {
-            var exception = new MissingPDFException('Missing PDF "' +
-                                                    source.url + '".');
+            exception = new MissingPDFException('Missing PDF "' +
+                                                source.url + '".');
             handler.send('MissingPDF', exception);
           } else {
-            handler.send('DocError', 'Unexpected server response (' +
-                         status + ') while retrieving PDF "' +
-                         source.url + '".');
+            exception = new UnexpectedResponseException(
+              'Unexpected server response (' + status +
+              ') while retrieving PDF "' + source.url + '".', status);
+            handler.send('UnexpectedResponse', exception);
           }
         },
 
@@ -208,6 +210,8 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
           handler.send('InvalidPDF', e);
         } else if (e instanceof MissingPDFException) {
           handler.send('MissingPDF', e);
+        } else if (e instanceof UnexpectedResponseException) {
+          handler.send('UnexpectedResponse', e);
         } else {
           handler.send('UnknownError',
                        new UnknownErrorException(e.message, e.toString()));
diff --git a/src/display/api.js b/src/display/api.js
index 5d13921..a8840db 100644
--- a/src/display/api.js
+++ b/src/display/api.js
@@ -16,9 +16,9 @@
  */
 /* globals PDFJS, isArrayBuffer, error, combineUrl, createPromiseCapability,
            StatTimer, globalScope, MessageHandler, info, FontLoader, Util, warn,
-           PasswordResponses, PasswordException, InvalidPDFException,
+           Promise, PasswordResponses, PasswordException, InvalidPDFException,
            MissingPDFException, UnknownErrorException, FontFace, loadJpegStream,
-           createScratchCanvas, Promise, CanvasGraphics */
+           createScratchCanvas, CanvasGraphics, UnexpectedResponseException */
 
 'use strict';
 
@@ -895,6 +895,12 @@ var WorkerTransport = (function WorkerTransportClosure() {
           new MissingPDFException(exception.message));
       }, this);
 
+      messageHandler.on('UnexpectedResponse',
+                        function transportUnexpectedResponse(exception) {
+        this.workerReadyCapability.reject(
+          new UnexpectedResponseException(exception.message, exception.status));
+      }, this);
+
       messageHandler.on('UnknownError',
                         function transportUnknownError(exception) {
         this.workerReadyCapability.reject(
@@ -994,10 +1000,6 @@ var WorkerTransport = (function WorkerTransportClosure() {
         }
       }, this);
 
-      messageHandler.on('DocError', function transportDocError(data) {
-        this.workerReadyCapability.reject(data);
-      }, this);
-
       messageHandler.on('PageError', function transportError(data) {
         var page = this.pageCache[data.pageNum - 1];
         var intentState = page.intentStates[data.intent];
diff --git a/src/shared/util.js b/src/shared/util.js
index 9d0d297..7deb991 100644
--- a/src/shared/util.js
+++ b/src/shared/util.js
@@ -384,6 +384,21 @@ var MissingPDFException = (function MissingPDFExceptionClosure() {
 })();
 PDFJS.MissingPDFException = MissingPDFException;
 
+var UnexpectedResponseException =
+    (function UnexpectedResponseExceptionClosure() {
+  function UnexpectedResponseException(msg, status) {
+    this.name = 'UnexpectedResponseException';
+    this.message = msg;
+    this.status = status;
+  }
+
+  UnexpectedResponseException.prototype = new Error();
+  UnexpectedResponseException.constructor = UnexpectedResponseException;
+
+  return UnexpectedResponseException;
+})();
+PDFJS.UnexpectedResponseException = UnexpectedResponseException;
+
 var NotImplementedException = (function NotImplementedExceptionClosure() {
   function NotImplementedException(msg) {
     this.message = msg;
diff --git a/web/viewer.js b/web/viewer.js
index d332a5e..04f0bb5 100644
--- a/web/viewer.js
+++ b/web/viewer.js
@@ -681,19 +681,18 @@ var PDFView = {
           // change error message also for other builds
           loadingErrorMessage = mozL10n.get('invalid_file_error', null,
                                             'Invalid or corrupted PDF file.');
-//#if B2G
-//        window.alert(loadingErrorMessage);
-//        return window.close();
-//#endif
         } else if (exception instanceof PDFJS.MissingPDFException) {
           // special message for missing PDF's
           loadingErrorMessage = mozL10n.get('missing_file_error', null,
                                             'Missing PDF file.');
+        } else if (exception instanceof PDFJS.UnexpectedResponseException) {
+          loadingErrorMessage = mozL10n.get('unexpected_response_error', null,
+                                            'Unexpected server response.');
+        }
 //#if B2G
-//        window.alert(loadingErrorMessage);
-//        return window.close();
+//      window.alert(loadingErrorMessage);
+//      return window.close();
 //#endif
-        }
 
         var moreInfo = {
           message: message

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/pdf.js.git



More information about the Pkg-javascript-commits mailing list