Add |UnexpectedResponseException| to fix the exception handling when file loading fails because the server responds with a non 404 status message
This commit is contained in:
parent
27a80f3b88
commit
ed5fc43510
@ -146,6 +146,7 @@ loading_error_indicator=Error
|
|||||||
loading_error=An error occurred while loading the PDF.
|
loading_error=An error occurred while loading the PDF.
|
||||||
invalid_file_error=Invalid or corrupted PDF file.
|
invalid_file_error=Invalid or corrupted PDF file.
|
||||||
missing_file_error=Missing 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.
|
# 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
|
# "{{type}}" will be replaced with an annotation type from a list defined in
|
||||||
|
@ -14,11 +14,11 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
/* globals error, globalScope, InvalidPDFException, info,
|
/* globals PDFJS, createPromiseCapability, LocalPdfManager, NetworkPdfManager,
|
||||||
MissingPDFException, PasswordException, PDFJS, Promise,
|
NetworkManager, isInt, RANGE_CHUNK_SIZE, MissingPDFException,
|
||||||
UnknownErrorException, NetworkManager, LocalPdfManager,
|
UnexpectedResponseException, PasswordException, Promise,
|
||||||
NetworkPdfManager, XRefParseException, createPromiseCapability,
|
PasswordResponses, InvalidPDFException, UnknownErrorException,
|
||||||
isInt, PasswordResponses, MessageHandler, Ref, RANGE_CHUNK_SIZE */
|
XRefParseException, Ref, info, globalScope, error, MessageHandler */
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
@ -141,14 +141,16 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
onError: function onError(status) {
|
onError: function onError(status) {
|
||||||
|
var exception;
|
||||||
if (status === 404) {
|
if (status === 404) {
|
||||||
var exception = new MissingPDFException('Missing PDF "' +
|
exception = new MissingPDFException('Missing PDF "' +
|
||||||
source.url + '".');
|
source.url + '".');
|
||||||
handler.send('MissingPDF', exception);
|
handler.send('MissingPDF', exception);
|
||||||
} else {
|
} else {
|
||||||
handler.send('DocError', 'Unexpected server response (' +
|
exception = new UnexpectedResponseException(
|
||||||
status + ') while retrieving PDF "' +
|
'Unexpected server response (' + status +
|
||||||
source.url + '".');
|
') while retrieving PDF "' + source.url + '".', status);
|
||||||
|
handler.send('UnexpectedResponse', exception);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -208,6 +210,8 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
|
|||||||
handler.send('InvalidPDF', e);
|
handler.send('InvalidPDF', e);
|
||||||
} else if (e instanceof MissingPDFException) {
|
} else if (e instanceof MissingPDFException) {
|
||||||
handler.send('MissingPDF', e);
|
handler.send('MissingPDF', e);
|
||||||
|
} else if (e instanceof UnexpectedResponseException) {
|
||||||
|
handler.send('UnexpectedResponse', e);
|
||||||
} else {
|
} else {
|
||||||
handler.send('UnknownError',
|
handler.send('UnknownError',
|
||||||
new UnknownErrorException(e.message, e.toString()));
|
new UnknownErrorException(e.message, e.toString()));
|
||||||
|
@ -16,9 +16,9 @@
|
|||||||
*/
|
*/
|
||||||
/* globals PDFJS, isArrayBuffer, error, combineUrl, createPromiseCapability,
|
/* globals PDFJS, isArrayBuffer, error, combineUrl, createPromiseCapability,
|
||||||
StatTimer, globalScope, MessageHandler, info, FontLoader, Util, warn,
|
StatTimer, globalScope, MessageHandler, info, FontLoader, Util, warn,
|
||||||
PasswordResponses, PasswordException, InvalidPDFException,
|
Promise, PasswordResponses, PasswordException, InvalidPDFException,
|
||||||
MissingPDFException, UnknownErrorException, FontFace, loadJpegStream,
|
MissingPDFException, UnknownErrorException, FontFace, loadJpegStream,
|
||||||
createScratchCanvas, Promise, CanvasGraphics */
|
createScratchCanvas, CanvasGraphics, UnexpectedResponseException */
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
@ -895,6 +895,12 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|||||||
new MissingPDFException(exception.message));
|
new MissingPDFException(exception.message));
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
|
messageHandler.on('UnexpectedResponse',
|
||||||
|
function transportUnexpectedResponse(exception) {
|
||||||
|
this.workerReadyCapability.reject(
|
||||||
|
new UnexpectedResponseException(exception.message, exception.status));
|
||||||
|
}, this);
|
||||||
|
|
||||||
messageHandler.on('UnknownError',
|
messageHandler.on('UnknownError',
|
||||||
function transportUnknownError(exception) {
|
function transportUnknownError(exception) {
|
||||||
this.workerReadyCapability.reject(
|
this.workerReadyCapability.reject(
|
||||||
@ -994,10 +1000,6 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|||||||
}
|
}
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
messageHandler.on('DocError', function transportDocError(data) {
|
|
||||||
this.workerReadyCapability.reject(data);
|
|
||||||
}, this);
|
|
||||||
|
|
||||||
messageHandler.on('PageError', function transportError(data) {
|
messageHandler.on('PageError', function transportError(data) {
|
||||||
var page = this.pageCache[data.pageNum - 1];
|
var page = this.pageCache[data.pageNum - 1];
|
||||||
var intentState = page.intentStates[data.intent];
|
var intentState = page.intentStates[data.intent];
|
||||||
|
@ -384,6 +384,21 @@ var MissingPDFException = (function MissingPDFExceptionClosure() {
|
|||||||
})();
|
})();
|
||||||
PDFJS.MissingPDFException = MissingPDFException;
|
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() {
|
var NotImplementedException = (function NotImplementedExceptionClosure() {
|
||||||
function NotImplementedException(msg) {
|
function NotImplementedException(msg) {
|
||||||
this.message = msg;
|
this.message = msg;
|
||||||
|
@ -681,19 +681,18 @@ var PDFView = {
|
|||||||
// change error message also for other builds
|
// change error message also for other builds
|
||||||
loadingErrorMessage = mozL10n.get('invalid_file_error', null,
|
loadingErrorMessage = mozL10n.get('invalid_file_error', null,
|
||||||
'Invalid or corrupted PDF file.');
|
'Invalid or corrupted PDF file.');
|
||||||
//#if B2G
|
|
||||||
// window.alert(loadingErrorMessage);
|
|
||||||
// return window.close();
|
|
||||||
//#endif
|
|
||||||
} else if (exception instanceof PDFJS.MissingPDFException) {
|
} else if (exception instanceof PDFJS.MissingPDFException) {
|
||||||
// special message for missing PDF's
|
// special message for missing PDF's
|
||||||
loadingErrorMessage = mozL10n.get('missing_file_error', null,
|
loadingErrorMessage = mozL10n.get('missing_file_error', null,
|
||||||
'Missing PDF file.');
|
'Missing PDF file.');
|
||||||
//#if B2G
|
} else if (exception instanceof PDFJS.UnexpectedResponseException) {
|
||||||
// window.alert(loadingErrorMessage);
|
loadingErrorMessage = mozL10n.get('unexpected_response_error', null,
|
||||||
// return window.close();
|
'Unexpected server response.');
|
||||||
//#endif
|
|
||||||
}
|
}
|
||||||
|
//#if B2G
|
||||||
|
// window.alert(loadingErrorMessage);
|
||||||
|
// return window.close();
|
||||||
|
//#endif
|
||||||
|
|
||||||
var moreInfo = {
|
var moreInfo = {
|
||||||
message: message
|
message: message
|
||||||
|
Loading…
x
Reference in New Issue
Block a user