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(download): show appropriate download error #1081

Merged
merged 3 commits into from
Oct 10, 2019
Merged

Conversation

priyajeet
Copy link
Contributor

@priyajeet priyajeet commented Oct 8, 2019

for when download might get disabled due to an access policy while the user is already previewing the file without browser refresh.

Also fixes the apostrophes

@priyajeet priyajeet requested a review from a team as a code owner October 8, 2019 00:39
@boxcla
Copy link

boxcla commented Oct 8, 2019

Verified that @priyajeet has signed the CLA. Thanks for the pull request!

sahiga
sahiga previously approved these changes Oct 8, 2019
const code = getProp(error, 'response.data.code');
let msg = downloadErrorMsg;
if (code === 'forbidden_by_policy') {
msg = __('notification_cannot_download_due_to_policy');
Copy link

Choose a reason for hiding this comment

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

Can you create constants for these strings?

*/
download() {
const downloadErrorMsg = __('notification_cannot_download');
if (!canDownload(this.file, this.options)) {
this.ui.showNotification(downloadErrorMsg);
return;
return Promise.reject();
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we reject with a reason?

@@ -513,25 +513,27 @@ class Preview extends EventEmitter {
* Downloads the file being previewed.
*
* @public
* @return {void}
* @return {Promise} download promise
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a public API for the preview instance, right? Is this considered a breaking change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am actually gonna remove the return promise. Only downside is that this function is not really being tested properly, specially for errors.

.get(getDownloadUrl, { headers: this.getRequestHeaders() })
.then(data => {
const downloadUrl = appendQueryParams(data.download_url, queryParams);
this.api.reachability.downloadWithReachabilityCheck(downloadUrl);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this return the promise result from downloadWithReachabilityCheck?

if (code === 'forbidden_by_policy') {
msg = __('notification_cannot_download_due_to_policy');
}
this.ui.showNotification(msg);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we do a Promise.reject here?

@@ -541,15 +543,25 @@ class Preview extends EventEmitter {
params,
);

this.api.reachability.downloadWithReachabilityCheck(downloadUrl);
downloadPromise = this.api.reachability.downloadWithReachabilityCheck(downloadUrl);
Copy link
Contributor

Choose a reason for hiding this comment

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

It doesn't look like downloadWithReachabilityCheck actually returns a promise?

@@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

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

What was wrong with the apostrophes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Normally for user facing strings one uses the accented versions. It also helps with not having the need to escape.

ConradJChan
ConradJChan previously approved these changes Oct 9, 2019
@mergify mergify bot merged commit 269c9ff into box:master Oct 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants