Skip to content

Commit

Permalink
fix(download): show appropriate download error (#1081)
Browse files Browse the repository at this point in the history
* fix(download): show appropiate download error

* fix: e2e test

* fix: adding e2e test instead for download errors
  • Loading branch information
priyajeet authored and mergify[bot] committed Oct 10, 2019
1 parent 670b85c commit 269c9ff
Show file tree
Hide file tree
Showing 13 changed files with 142 additions and 97 deletions.
14 changes: 7 additions & 7 deletions src/i18n/en-AU.properties
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ has_x_refs=This preview has references you cannot view. Open the file in its nat

# Error messages
# Default preview error message
error_generic=We're sorry, the preview didn't load.
error_generic=Were sorry, the preview didn't load.
# Default preview error message
error_unsupported=We're sorry, we can't preview this file type in your web browser. To view this content, please download and open it on your device.
error_unsupported=Were sorry, we can't preview this file type in your web browser. To view this content, please download and open it on your device.
# 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.
error_account=Were sorry, your account is unable to preview this file type.
# No permissions preview error message
error_permissions=Sorry! You don't have permission to preview this file.
# Preview refresh error message suggesting refreshing the page as a possible fix
Expand All @@ -59,15 +59,15 @@ error_browser_unsupported=Sorry! Your browser doesn't support preview for {1}.
# Preview error message shown when document loading fails (most likely due to password or watermark)
error_document=Sorry! The preview hasn't loaded. This document may be protected.
# Preview error message shown when the document is password protected
error_password_protected=We're sorry, but the preview didn't load. This document is protected.
error_password_protected=Were sorry, but the preview didn't load. This document is protected.
# Preview error message shown when conversion was unable to process the file at the given time.
error_try_again_later=We're sorry, but the preview didn't load. Please try again later.
error_try_again_later=Were sorry, but the preview didn't load. Please try again later.
# Preview error message shown when conversion failed due to file contents
error_bad_file=We're sorry the preview didn't load. This file could not be converted.
error_bad_file=Were sorry the preview didnt load. This file could not be converted.
# Preview error message shown when the file cannot be downloaded
error_not_downloadable=Oops! It looks as if something is wrong with this file. We apologise for the inconvenience and recommend that you upload a new version of this file or roll back to a previous version. Please contact us for more details.
# Preview error message shown when flash is not enabled on their browser
error_flash_not_enabled=We're sorry, the preview did not load because Flash is not enabled on your browser. If possible, please enable Flash and refresh the page.
error_flash_not_enabled=Were sorry, the preview did not load because Flash is not enabled on your browser. If possible, please enable Flash and refresh the page.

# Media Preview
# Label for autoplay in media player
Expand Down
32 changes: 16 additions & 16 deletions src/i18n/en-CA.properties
Original file line number Diff line number Diff line change
Expand Up @@ -41,33 +41,33 @@ has_x_refs=This preview has references you cannot view. Open the file in its nat

# Error messages
# Default preview error message
error_generic=We're sorry, the preview didn't load.
error_generic=Were sorry, the preview didn't load.
# Default preview error message
error_unsupported=We're sorry, we can't preview this file type in your web browser. To view this content please download and open it on your device.
error_unsupported=Were sorry, we can't preview this file type in your web browser. To view this content please download and open it on your device.
# 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.
error_account=Were sorry, your account is unable to preview this file type.
# No permissions preview error message
error_permissions=We're sorry, you don't have permission to preview this file.
error_permissions=Were sorry, you don't have permission to preview this file.
# Preview refresh error message suggesting refreshing the page as a possible fix
error_refresh=We're sorry, the preview didn't load. Please refresh the page.
error_refresh=Were sorry, the preview didn't load. Please refresh the page.
# Preview rate limit error suggesting waiting a few minutes to avoid rate limit
error_rate_limit=We're sorry, the preview didn't load because your request was rate limited. Please wait a few minutes and try again.
error_rate_limit=Were sorry, the preview didn't load because your request was rate limited. Please wait a few minutes and try again.
# Preview re-upload error message suggesting re-uploading the file or contacting support as a possible fix
error_reupload=We're sorry, the preview didn't load. Please re-upload the file or contact Box support.
error_reupload=Were sorry, the preview didn't load. Please re-upload the file or contact Box support.
# Preview error message shown when the user's browser doesn't support previews of this file type
error_browser_unsupported=We're sorry, your browser doesn't support preview for {1}.
error_browser_unsupported=Were sorry, your browser doesn't support preview for {1}.
# Preview error message shown when document loading fails (most likely due to password or watermark)
error_document=We're sorry, the preview didn't load. This document may be protected.
error_document=Were sorry, the preview didn't load. This document may be protected.
# Preview error message shown when the document is password protected
error_password_protected=We're sorry the preview didn't load. This document is protected.
error_password_protected=Were sorry the preview didnt load. This document is protected.
# Preview error message shown when conversion was unable to process the file at the given time.
error_try_again_later=We're sorry the preview didn't load. Please try again later.
error_try_again_later=Were sorry the preview didnt load. Please try again later.
# Preview error message shown when conversion failed due to file contents
error_bad_file=We're sorry the preview didn't load. This file could not be converted.
error_bad_file=Were sorry the preview didnt load. This file could not be converted.
# Preview error message shown when the file cannot be downloaded
error_not_downloadable=Oops! It looks like something is wrong with this file. We apologize for the inconvenience and recommend that you upload a new version of this file or roll back to a previous version. Please contact us for more details.
# Preview error message shown when flash is not enabled on their browser
error_flash_not_enabled=We're sorry, the preview didn't load because Flash is not enabled on your browser. If possible, please enable Flash and refresh the page.
error_flash_not_enabled=Were sorry, the preview didn't load because Flash is not enabled on your browser. If possible, please enable Flash and refresh the page.

# Media Preview
# Label for autoplay in media player
Expand Down Expand Up @@ -171,11 +171,11 @@ annotation_draw_save=Save drawing
# Accessibilty text for button that soft deletes drawing
annotation_draw_delete=Delete drawing
# Text for when annotations fail to load
annotations_load_error=We're sorry, annotations failed to load for this file.
annotations_load_error=Were sorry, annotations failed to load for this file.
# Text for when the annotation can't be created
annotations_create_error=We're sorry, the annotation could not be created.
annotations_create_error=Were sorry, the annotation could not be created.
# Text for when the annotation can't be deleted
annotations_delete_error=We're sorry, the annotation could not be deleted.
annotations_delete_error=Were sorry, the annotation could not be deleted.
# Text for when the authorization token is invalid
annotations_authorization_error=Your session has expired. Please refresh the page.

Expand Down
14 changes: 7 additions & 7 deletions src/i18n/en-GB.properties
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ has_x_refs=This preview has references you cannot view. Open the file in its nat

# Error messages
# Default preview error message
error_generic=We're sorry, the preview didn't load.
error_generic=Were sorry, the preview didn't load.
# Default preview error message
error_unsupported=We're sorry, we can't preview this file type in your web browser. To view this content, please download and open it on your device.
error_unsupported=Were sorry, we can't preview this file type in your web browser. To view this content, please download and open it on your device.
# 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.
error_account=Were sorry, your account is unable to preview this file type.
# No permissions preview error message
error_permissions=Sorry! You don't have permission to preview this file.
# Preview refresh error message suggesting refreshing the page as a possible fix
Expand All @@ -59,15 +59,15 @@ error_browser_unsupported=Sorry! Your browser doesn't support preview for {1}.
# Preview error message shown when document loading fails (most likely due to password or watermark)
error_document=Sorry! The preview hasn't loaded. This document may be protected.
# Preview error message shown when the document is password protected
error_password_protected=We're sorry, but the preview didn't load. This document is protected.
error_password_protected=Were sorry, but the preview didn't load. This document is protected.
# Preview error message shown when conversion was unable to process the file at the given time.
error_try_again_later=We're sorry, but the preview didn't load. Please try again later.
error_try_again_later=Were sorry, but the preview didn't load. Please try again later.
# Preview error message shown when conversion failed due to file contents
error_bad_file=We're sorry the preview didn't load. This file could not be converted.
error_bad_file=Were sorry the preview didnt load. This file could not be converted.
# Preview error message shown when the file cannot be downloaded
error_not_downloadable=Oops! It looks as if something is wrong with this file. We apologise for the inconvenience and recommend that you upload a new version of this file or roll back to a previous version. Please contact us for more details.
# Preview error message shown when flash is not enabled on their browser
error_flash_not_enabled=We're sorry, the preview did not load because Flash is not enabled on your browser. If possible, please enable Flash and refresh the page.
error_flash_not_enabled=Were sorry, the preview did not load because Flash is not enabled on your browser. If possible, please enable Flash and refresh the page.

# Media Preview
# Label for autoplay in media player
Expand Down
44 changes: 23 additions & 21 deletions src/i18n/en-US.properties
Original file line number Diff line number Diff line change
Expand Up @@ -41,33 +41,33 @@ has_x_refs=This preview has references you cannot view. Open the file in its nat

# Error messages
# Default preview error message
error_generic=We're sorry, the preview didn't load.
error_generic=Were sorry, the preview didnt load.
# Default preview error message
error_unsupported=We're sorry, we can't preview this file type in your web browser. To view this content please download and open it on your device.
# 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.
error_unsupported=Were sorry, we cant preview this file type in your web browser. To view this content please download and open it on your device.
# Account doesnt have a sufficient tariff to preview the requested file type
error_account=Were sorry, your account is unable to preview this file type.
# No permissions preview error message
error_permissions=We're sorry, you don't have permission to preview this file.
error_permissions=Were sorry, you dont have permission to preview this file.
# Preview refresh error message suggesting refreshing the page as a possible fix
error_refresh=We're sorry, the preview didn't load. Please refresh the page.
error_refresh=Were sorry, the preview didnt load. Please refresh the page.
# Preview rate limit error suggesting waiting a few minutes to avoid rate limit
error_rate_limit=We're sorry, the preview didn't load because your request was rate limited. Please wait a few minutes and try again.
error_rate_limit=Were sorry, the preview didnt load because your request was rate limited. Please wait a few minutes and try again.
# Preview re-upload error message suggesting re-uploading the file or contacting support as a possible fix
error_reupload=We're sorry, the preview didn't load. Please re-upload the file or contact Box support.
# Preview error message shown when the user's browser doesn't support previews of this file type
error_browser_unsupported=We're sorry, your browser doesn't support preview for {1}.
error_reupload=Were sorry, the preview didnt load. Please re-upload the file or contact Box support.
# Preview error message shown when the users browser doesnt support previews of this file type
error_browser_unsupported=Were sorry, your browser doesnt support preview for {1}.
# Preview error message shown when document loading fails (most likely due to password or watermark)
error_document=We're sorry, the preview didn't load. This document may be protected.
error_document=Were sorry, the preview didnt load. This document may be protected.
# Preview error message shown when the document is password protected
error_password_protected=We're sorry the preview didn't load. This document is protected.
error_password_protected=Were sorry the preview didnt load. This document is protected.
# Preview error message shown when conversion was unable to process the file at the given time.
error_try_again_later=We're sorry the preview didn't load. Please try again later.
error_try_again_later=Were sorry the preview didnt load. Please try again later.
# Preview error message shown when conversion failed due to file contents
error_bad_file=We're sorry the preview didn't load. This file could not be converted.
error_bad_file=Were sorry the preview didnt load. This file could not be converted.
# Preview error message shown when the file cannot be downloaded
error_not_downloadable=Oops! It looks like something is wrong with this file. We apologize for the inconvenience and recommend that you upload a new version of this file or roll back to a previous version. Please contact us for more details.
# Preview error message shown when flash is not enabled on their browser
error_flash_not_enabled=We're sorry, the preview didn't load because Flash is not enabled on your browser. If possible, please enable Flash and refresh the page.
error_flash_not_enabled=Were sorry, the preview didnt load because Flash is not enabled on your browser. If possible, please enable Flash and refresh the page.

# Media Preview
# Label for autoplay in media player
Expand Down Expand Up @@ -171,11 +171,11 @@ annotation_draw_save=Save drawing
# Accessibilty text for button that soft deletes drawing
annotation_draw_delete=Delete drawing
# Text for when annotations fail to load
annotations_load_error=We're sorry, annotations failed to load for this file.
# Text for when the annotation can't be created
annotations_create_error=We're sorry, the annotation could not be created.
# Text for when the annotation can't be deleted
annotations_delete_error=We're sorry, the annotation could not be deleted.
annotations_load_error=Were sorry, annotations failed to load for this file.
# Text for when the annotation cant be created
annotations_create_error=Were sorry, the annotation could not be created.
# Text for when the annotation cant be deleted
annotations_delete_error=Were sorry, the annotation could not be deleted.
# Text for when the authorization token is invalid
annotations_authorization_error=Your session has expired. Please refresh the page.

Expand All @@ -191,7 +191,9 @@ notification_annotation_draw_mode=Press down and drag the pointer to draw on the
# Notification message shown when the user has a degraded preview experience due to blocked download hosts
notification_degraded_preview=It looks like your connection to {1} is being blocked. We think we can make file previews faster for you. To do that, please ask your network admin to configure firewall settings so that {1} is reachable.
# Notification message shown when a file cannot be downloaded
notification_cannot_download=Sorry! You can't download this file.
notification_cannot_download=Sorry! You can’t download this file.
# Notification message shown when a file cannot be downloaded due to an access policy
notification_cannot_download_due_to_policy=Downloading of this content has been disabled based on an access policy.

# Link Text
link_contact_us=Contact Us
Expand Down
19 changes: 15 additions & 4 deletions src/lib/Preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
API_HOST,
APP_HOST,
CLASS_NAVIGATION_VISIBILITY,
ERROR_CODE_403_FORBIDDEN_BY_POLICY,
PERMISSION_PREVIEW,
PREVIEW_SCRIPT_NAME,
X_REP_HINT_BASE,
Expand Down Expand Up @@ -517,6 +518,8 @@ class Preview extends EventEmitter {
*/
download() {
const downloadErrorMsg = __('notification_cannot_download');
const downloadErrorDueToPolicyMsg = __('notification_cannot_download_due_to_policy');

if (!canDownload(this.file, this.options)) {
this.ui.showNotification(downloadErrorMsg);
return;
Expand Down Expand Up @@ -546,10 +549,18 @@ class Preview extends EventEmitter {
// Otherwise, get the content download URL of the original file and download
} else {
const getDownloadUrl = appendQueryParams(getDownloadURL(this.file.id, apiHost), queryParams);
this.api.get(getDownloadUrl, { headers: this.getRequestHeaders() }).then(data => {
const downloadUrl = appendQueryParams(data.download_url, queryParams);
this.api.reachability.downloadWithReachabilityCheck(downloadUrl);
});
this.api
.get(getDownloadUrl, { headers: this.getRequestHeaders() })
.then(data => {
const downloadUrl = appendQueryParams(data.download_url, queryParams);
this.api.reachability.downloadWithReachabilityCheck(downloadUrl);
})
.catch(error => {
const code = getProp(error, 'response.data.code');
const msg =
code === ERROR_CODE_403_FORBIDDEN_BY_POLICY ? downloadErrorDueToPolicyMsg : downloadErrorMsg;
this.ui.showNotification(msg);
});
}

const downloadAttemptEvent = {
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 @@ -1670,7 +1670,7 @@ describe('lib/Preview', () => {
stubs.checkPermission.withArgs(sinon.match.any, PERMISSION_PREVIEW).returns(false);
expect(() => preview.loadViewer()).to.throw(
PreviewError,
/We're sorry, you don't have permission to preview this file./,
/Were sorry, you dont have permission to preview this file./,
);
});

Expand Down
4 changes: 2 additions & 2 deletions src/lib/__tests__/PreviewError-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ describe('lib/PreviewError', () => {

it('should default display message to generic error message if not provided', () => {
const previewError = new PreviewError('some_code');
expect(previewError.displayMessage).to.equal("We're sorry, the preview didn't load.");
expect(previewError.displayMessage).to.equal('We’re sorry, the preview didnt load.');
});

it('should default message to display message if message is not provided', () => {
const previewError = new PreviewError('some_code');
expect(previewError.message).to.equal("We're sorry, the preview didn't load.");
expect(previewError.message).to.equal('We’re sorry, the preview didnt load.');
});
});
});
3 changes: 3 additions & 0 deletions src/lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,6 @@ export const METADATA = {
SCOPE_GLOBAL: 'global',
TEMPLATE_AUTOCAD: 'autocad',
};

// Error Codes
export const ERROR_CODE_403_FORBIDDEN_BY_POLICY = 'forbidden_by_policy';
Loading

0 comments on commit 269c9ff

Please sign in to comment.