Skip to content

Commit

Permalink
fix for mozilla#2219, "provide a better error message when file= not …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
Bill Walker committed Jan 29, 2013
1 parent 7bd8887 commit 12af2f9
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 2 deletions.
1 change: 1 addition & 0 deletions l10n/en-US/viewer.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 12 additions & 0 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 15 additions & 2 deletions src/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ var WorkerMessageHandler = {
exception: e
});

return;
} else if (e instanceof MissingPDFException) {
handler.send('MissingPDF', {
exception: e
});

return;
} else {
handler.send('UnknownError', {
Expand Down Expand Up @@ -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
},
Expand Down
11 changes: 11 additions & 0 deletions web/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 12af2f9

Please sign in to comment.