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: Better error message for file of unknown type #862

Merged
merged 4 commits into from
Nov 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/i18n/en-US.properties
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ text_truncated=This file has been truncated due to size limits. Please download
# Default preview error message
error_generic=We're sorry, the preview didn't load.
# Default preview error message
error_unsupported=We're sorry, the preview didn't load. {1} files are not currently supported.
error_unsupported=We're sorry, this file type is not currently supported.
# Account doesn't have a sufficient tariff to preview the requested file type
error_account=We're sorry, your account is unable to preview this file type.
# No permissions preview error message
Expand Down
15 changes: 10 additions & 5 deletions src/lib/Preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
getHeaders,
findScriptLocation,
appendQueryParams,
replacePlaceholders,
stripAuthFromString,
isValidFileId,
isBoxWebApp,
Expand Down Expand Up @@ -1116,10 +1115,16 @@ class Preview extends EventEmitter {
return viewer.EXT.indexOf(this.file.extension) > -1;
});

const code = isFileTypeSupported ? ERROR_CODE.ACCOUNT : ERROR_CODE.UNSUPPORTED_FILE_TYPE;
const message = isFileTypeSupported
? __('error_account')
: replacePlaceholders(__('error_unsupported'), [(this.file.extension || '').toUpperCase()]);
let code;
let message;
// If the file type is supported, then the default error is account related
if (isFileTypeSupported) {
code = ERROR_CODE.ACCOUNT;
message = __('error_account');
} else {
code = ERROR_CODE.UNSUPPORTED_FILE_TYPE;
message = __('error_unsupported');
}

throw new PreviewError(code, message);
}
Expand Down
3 changes: 1 addition & 2 deletions src/lib/__tests__/Preview-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1617,13 +1617,12 @@ describe('lib/Preview', () => {
});

it('should throw an unsupported error if there is no loader for general file types', () => {
preview.file.extension = 'zip';
stubs.getLoader.returns(undefined);

try {
preview.loadViewer();
} catch (e) {
expect(e.message).to.equal(util.replacePlaceholders(__('error_unsupported'), ['ZIP']));
expect(e.message).to.equal(__('error_unsupported'));
}
});

Expand Down