Skip to content

Commit

Permalink
Fix: Ensure we are displaying a valid error string (#414)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Press authored Oct 5, 2017
1 parent 9a7882c commit ec908ba
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/lib/viewers/error/PreviewErrorViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ class PreviewErrorViewer extends BaseViewer {
/* eslint-enable no-param-reassign */

// If there is no display message fallback to the message from above
const displayMessage = err.displayMessage || err.message;
let displayMessage = err.displayMessage || err.message;
displayMessage = typeof displayMessage === 'string' ? displayMessage : __('error_default');

this.iconEl.innerHTML = icon;
this.messageEl.textContent = displayMessage;
Expand Down
11 changes: 11 additions & 0 deletions src/lib/viewers/error/__tests__/PreviewErrorViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,17 @@ describe('lib/viewers/error/PreviewErrorViewer', () => {
expect(error.addDownloadButton).to.not.be.called;
});

it('set the display message to the fallback error if the original display message is not a string', () => {
const err = new Error();
err.displayMessage = {
error: 'error!'
};

error.load(err);

expect(error.messageEl.textContent).to.equal(__('error_default'));
});

it('should not add download button if the browser cannot download', () => {
sandbox.stub(error, 'addDownloadButton');
sandbox.stub(Browser, 'canDownload').returns(false);
Expand Down

0 comments on commit ec908ba

Please sign in to comment.