Skip to content

Commit

Permalink
Fix: Better error message for file of unknown type (#862)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Press authored Nov 16, 2018
1 parent 3d7cf79 commit de1246a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
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

0 comments on commit de1246a

Please sign in to comment.