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

Update: Add un-downloadable error case #667

Merged
merged 1 commit into from
Feb 20, 2018

Conversation

tonyjin
Copy link
Contributor

@tonyjin tonyjin commented Feb 15, 2018

Add error message for un-downloadable file and support for a link button instead of a download button in the error viewer.

@boxcla
Copy link

boxcla commented Feb 15, 2018

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

// Add optional download button
if (checkPermission(file, PERMISSION_DOWNLOAD) && showDownload && Browser.canDownload()) {
// Add optional link or download button
const { linkMsg, linkUrl } = err;
Copy link
Contributor

Choose a reason for hiding this comment

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

Where are we adding this linkUrl to the error object?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In a separate patch when the field is ready.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ignore what I said, I've added the check for is_download_available into this patch now.

@@ -923,6 +924,16 @@ class Preview extends EventEmitter {
this.file = file;
this.logger.setFile(file);

// If file is not downloadable, trigger an error
if (file.is_download_available === false) {
const error = createPreviewError(ERROR_CODE.notDownloadable, __('error_not_downloadable'), null, {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@JustinHoldstock am I using createPreviewError() right here? I'm not clear on what the third param will be used for - I see it can be any type, string, obj, Error. Are we parsing that at the WebApp level?

Also const error = createPreviewError(ERROR_CODE.prefetchFile, null, err); on https://github.com/box/box-content-preview/blob/master/src/lib/Preview.js#L550 might not be doing what you expect since null will be explicitly assigned to displayMessage. Default function parameters are only used when you pass no value or undefined: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Default_parameters

Copy link
Contributor

Choose a reason for hiding this comment

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

The third param should be the details of the error. You can remove the third param, null.

The second param of the function is set to the displayMessage property of the error created. The third is set to the message property of the error created.

Aww hell, I forgot that null wouldn't work with default params. I will make a ticket to update anywhere using null

Copy link
Contributor

Choose a reason for hiding this comment

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

Just saw what you did there, with the fourth param. See comment below

@@ -1497,7 +1508,7 @@ class Preview extends EventEmitter {
console.error(message);
/* eslint-enable no-console */

const error = createPreviewError(ERROR_CODE, message, filesToPrefetch);
const error = createPreviewError(ERROR_CODE.prefetchFile, message, filesToPrefetch);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@JustinHoldstock we also want a specific code here right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes. I apologize for missing that one. Thanks for catching it

Object.keys(properties).forEach((key) => {
error[key] = properties[key];
});
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@JustinHoldstock I wonder if there's an opportunity to combine details and properties here. Maybe I can put linkText and linkUrl inside details and check that? It just feels a bit odd to be checking error.message.linkText and error.message.linkUrl in my logic in PreviewErrorViewer.

Open to other thoughts here.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would say anything you want logged to the backend needs to be stored in message. If you want linkUrl and linkText to be sent with error details for debugging purposes, I'd agree that it makes sense to fold them into details. My only issue with that is we end up sending a translated string.

Copy link
Contributor

Choose a reason for hiding this comment

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

One other note, I'm quite opposed to us dynamically creating properties on an already defined object type (Error). Now may be a good time for us to consider having our own class that extends Error, with our additional props on it, and only using that when creating errors in Preview.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@JustinHoldstock are you okay with my merging this as-is and then following up with a refactor? There are a lot of places I'd have to touch for a Previewer for refactor and 1) I'd like to get this change in before the release cut tomorrow and 2) I probably want that larger change in a separate PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Absolutely! :D

const linkBtnEl = this.infoEl.appendChild(document.createElement('a'));
linkBtnEl.className = 'bp-btn bp-btn-primary';
linkBtnEl.target = '_blank';
linkBtnEl.textContent = linkText;
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 be localized too?

Copy link
Contributor Author

@tonyjin tonyjin Feb 16, 2018

Choose a reason for hiding this comment

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

I'll add documentation to the JSDoc that this should be localized before passed in.

Show an error message when a file is undownloadable.
@tonyjin tonyjin force-pushed the add-undownloadable-error-case branch from 98a35b1 to 6edd67e Compare February 20, 2018 19:54
@tonyjin tonyjin merged commit 28a64aa into box:master Feb 20, 2018
@tonyjin tonyjin deleted the add-undownloadable-error-case branch February 20, 2018 20:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants