1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-25 17:48:07 +02:00

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:
Jonas Jenwald 2014-09-13 16:47:16 +02:00
parent 27a80f3b88
commit ed5fc43510
5 changed files with 45 additions and 24 deletions

View file

@ -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()));