1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

Merge pull request #5275 from Snuffleupagus/exception-propagation

Fix the exception propagation when rejecting workerReadyCapability
This commit is contained in:
Yury Delendik 2014-09-16 10:05:34 -05:00
commit ffb613bbac
6 changed files with 124 additions and 84 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 + '".');
handler.send('MissingPDF', { exception: exception });
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);
}
},
@ -200,26 +202,19 @@ var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
var onFailure = function(e) {
if (e instanceof PasswordException) {
if (e.code === PasswordResponses.NEED_PASSWORD) {
handler.send('NeedPassword', {
exception: e
});
handler.send('NeedPassword', e);
} else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
handler.send('IncorrectPassword', {
exception: e
});
handler.send('IncorrectPassword', e);
}
} else if (e instanceof InvalidPDFException) {
handler.send('InvalidPDF', {
exception: e
});
handler.send('InvalidPDF', e);
} else if (e instanceof MissingPDFException) {
handler.send('MissingPDF', {
exception: e
});
handler.send('MissingPDF', e);
} else if (e instanceof UnexpectedResponseException) {
handler.send('UnexpectedResponse', e);
} else {
handler.send('UnknownError', {
exception: new UnknownErrorException(e.message, e.toString())
});
handler.send('UnknownError',
new UnknownErrorException(e.message, e.toString()));
}
};

View file

@ -14,11 +14,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* globals CanvasGraphics, combineUrl, createScratchCanvas, error,
FontLoader, globalScope, info, isArrayBuffer, loadJpegStream,
MessageHandler, PDFJS, Promise, StatTimer, warn,
PasswordResponses, Util, loadScript, createPromiseCapability,
FontFace */
/* globals PDFJS, isArrayBuffer, error, combineUrl, createPromiseCapability,
StatTimer, globalScope, MessageHandler, info, FontLoader, Util, warn,
Promise, PasswordResponses, PasswordException, InvalidPDFException,
MissingPDFException, UnknownErrorException, FontFace, loadJpegStream,
createScratchCanvas, CanvasGraphics, UnexpectedResponseException */
'use strict';
@ -865,36 +865,46 @@ var WorkerTransport = (function WorkerTransportClosure() {
this.workerReadyCapability.resolve(pdfDocument);
}, this);
messageHandler.on('NeedPassword', function transportPassword(data) {
messageHandler.on('NeedPassword',
function transportNeedPassword(exception) {
if (this.passwordCallback) {
return this.passwordCallback(updatePassword,
PasswordResponses.NEED_PASSWORD);
}
this.workerReadyCapability.reject(data.exception.message,
data.exception);
this.workerReadyCapability.reject(
new PasswordException(exception.message, exception.code));
}, this);
messageHandler.on('IncorrectPassword', function transportBadPass(data) {
messageHandler.on('IncorrectPassword',
function transportIncorrectPassword(exception) {
if (this.passwordCallback) {
return this.passwordCallback(updatePassword,
PasswordResponses.INCORRECT_PASSWORD);
}
this.workerReadyCapability.reject(data.exception.message,
data.exception);
this.workerReadyCapability.reject(
new PasswordException(exception.message, exception.code));
}, this);
messageHandler.on('InvalidPDF', function transportInvalidPDF(data) {
this.workerReadyCapability.reject(data.exception.name, data.exception);
messageHandler.on('InvalidPDF', function transportInvalidPDF(exception) {
this.workerReadyCapability.reject(
new InvalidPDFException(exception.message));
}, this);
messageHandler.on('MissingPDF', function transportMissingPDF(data) {
this.workerReadyCapability.reject(data.exception.message,
data.exception);
messageHandler.on('MissingPDF', function transportMissingPDF(exception) {
this.workerReadyCapability.reject(
new MissingPDFException(exception.message));
}, this);
messageHandler.on('UnknownError', function transportUnknownError(data) {
this.workerReadyCapability.reject(data.exception.message,
data.exception);
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(
new UnknownErrorException(exception.message, exception.details));
}, this);
messageHandler.on('DataLoaded', function transportPage(data) {
@ -990,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];

View file

@ -342,6 +342,7 @@ var PasswordException = (function PasswordExceptionClosure() {
return PasswordException;
})();
PDFJS.PasswordException = PasswordException;
var UnknownErrorException = (function UnknownErrorExceptionClosure() {
function UnknownErrorException(msg, details) {
@ -355,6 +356,7 @@ var UnknownErrorException = (function UnknownErrorExceptionClosure() {
return UnknownErrorException;
})();
PDFJS.UnknownErrorException = UnknownErrorException;
var InvalidPDFException = (function InvalidPDFExceptionClosure() {
function InvalidPDFException(msg) {
@ -367,6 +369,7 @@ var InvalidPDFException = (function InvalidPDFExceptionClosure() {
return InvalidPDFException;
})();
PDFJS.InvalidPDFException = InvalidPDFException;
var MissingPDFException = (function MissingPDFExceptionClosure() {
function MissingPDFException(msg) {
@ -379,6 +382,22 @@ var MissingPDFException = (function MissingPDFExceptionClosure() {
return 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() {
function NotImplementedException(msg) {