Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Display correct error when handling an asset error #829

Merged
merged 1 commit into from
Aug 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, {});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If handleAssetError is called with a preview error, we should use that instead of creating a generic load asset error. More specific error types were replaced here.

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