Skip to content

Commit

Permalink
Fix: Display correct error when handling an asset error (#829)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Press authored Aug 16, 2018
1 parent 4fd4258 commit 2f70273
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib/viewers/BaseViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ class BaseViewer extends EventEmitter {
*/
handleAssetError(err) {
const originalMessage = err ? err.message : '';
const error = new PreviewError(ERROR_CODE.LOAD_ASSET, '', {}, originalMessage);
const error = err instanceof PreviewError ? err : new PreviewError(ERROR_CODE.LOAD_ASSET, originalMessage, {});
this.triggerError(error);
this.destroyed = true;
}
Expand Down
7 changes: 7 additions & 0 deletions src/lib/viewers/__tests__/BaseViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,13 @@ describe('lib/viewers/BaseViewer', () => {
expect(base.destroyed).to.be.true;
});

it('should use the original error if it is a PreviewError', () => {
sandbox.stub(base, 'triggerError');
const originalError = new PreviewError('foo', 'bar');
base.handleAssetError(originalError);
expect(base.triggerError).to.be.calledWith(originalError);
});

it('should pass along the error if provided', () => {
const stub = sandbox.stub(base, 'triggerError');

Expand Down

0 comments on commit 2f70273

Please sign in to comment.