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 1 commit
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: 2 additions & 0 deletions src/i18n/en-US.properties
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ text_truncated=This file has been truncated due to size limits. Please download
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.
# Preview error message for an unknown file type.
error_unsupported_unknown_type=We're sorry, the preview didn't load. This file 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
16 changes: 12 additions & 4 deletions src/lib/Preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -1116,10 +1116,18 @@ 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 = this.file.extension
? replacePlaceholders(__('error_unsupported'), [this.file.extension])
: __('error_unsupported_unknown_type');
}

throw new PreviewError(code, message);
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/__tests__/Preview-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1623,7 +1623,7 @@ describe('lib/Preview', () => {
try {
preview.loadViewer();
} catch (e) {
expect(e.message).to.equal(util.replacePlaceholders(__('error_unsupported'), ['ZIP']));
expect(e.message).to.equal(util.replacePlaceholders(__('error_unsupported'), ['zip']));
}
});

Expand Down