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

ShareWrapper: Abort upload and show feedback when file upload fails #5661

Merged
merged 3 commits into from
Feb 16, 2023

Conversation

chrisbobbe
Copy link
Contributor

Related: #5660

@chrisbobbe chrisbobbe requested a review from gnprice February 15, 2023 02:19
Copy link
Member

@gnprice gnprice left a comment

Choose a reason for hiding this comment

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

Thanks! Comments below.

Comment on lines 174 to 187
let msg = undefined;
if (error instanceof ApiError && error.message.length > 0) {
msg = error.message;
}

// TODO: handle other kinds of errors

this.setState({ sending: false });
showErrorAlert(_('Failed to upload file: {fileName}', { fileName }), msg);
Copy link
Member

Choose a reason for hiding this comment

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

How about using error.message for all Error instances, not just ApiError?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. The message won't always be good user-facing text, but at least it'll help us debug when we get reports.

Comment on lines 169 to 171
if (!(error instanceof Error)) {
logging.error('ShareWrapper: Unexpected non-error thrown');
return;
}
Copy link
Member

Choose a reason for hiding this comment

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

If this somehow happens, seems best to still give the user feedback. Just won't have a message for them.

@chrisbobbe chrisbobbe force-pushed the pr-sharing-feedback-upload-fails branch from 0767b8f to 64a5a8c Compare February 16, 2023 17:47
@chrisbobbe
Copy link
Contributor Author

Thanks for the review! Revision pushed.

Copy link
Member

@gnprice gnprice left a comment

Choose a reason for hiding this comment

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

Thanks! Comments below.

Comment on lines 175 to 177
error instanceof ApiError
&& error.code === 413 // 413 Payload Too Large:
// https://chat.zulip.org/#narrow/stream/412-api-documentation/topic/.2Fuser_uploads.3A.20.60413.20Payload.20Too.20Large.60/near/1332958
Copy link
Member

Choose a reason for hiding this comment

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

This should say instanceof RequestError, rather than ApiError.

When we get this status code, it may not be from the Zulip server application with its well-formed Zulip API error blob — it may be from something like nginx sitting in front of it. So that won't be an ApiError.

Oh also 413 isn't a Zulip API error code, so it won't be a value of ApiError.code:

export class ApiError extends RequestError {
  +code: ApiErrorCode;
// …

/**
 * An identifier-like string identifying a Zulip API error. …
 */
export type ApiErrorCode = string;

Instead this should be error.httpStatus. See RequestError.

&& error.code === 413 // 413 Payload Too Large:
// https://chat.zulip.org/#narrow/stream/412-api-documentation/topic/.2Fuser_uploads.3A.20.60413.20Payload.20Too.20Large.60/near/1332958
) {
msg = _('This file is too large.');
Copy link
Member

Choose a reason for hiding this comment

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

Let's make this say: "The server said the file is too large."

I.e., make clear that it's the server that made this judgement, not the client app.

In a lot of apps, where the server and client are provided by the same organization, making that distinction would be bad UI practice. But for Zulip I think it's appropriate because it helps the user figure out who to complain to.

(At first I wrote "The server rejected the file. The file is too large." (I considered "The server rejected the file as too large", but I think that syntax is a bit too complex for good UI writing.) But then while writing the next comment I realized that this gets shown below a heading saying "Failed to upload file". So it can be simplified.)

Comment on lines +180 to +184
} else if (error instanceof Error && error.message.length > 0) {
msg = error.message;
}
Copy link
Member

Choose a reason for hiding this comment

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

That gives me a related thought: let's have this generic Error case, but before this let's say something like: if it's an ApiError, then msg = _('The server said: {errorMessage}', { errorMessage: error.message }).

That way again the attribution is clear.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense. I put \n\n in this revision for consistency with a similar message we show in the login flow: The server at {realm} said:\n\n{message}

@chrisbobbe chrisbobbe force-pushed the pr-sharing-feedback-upload-fails branch from 64a5a8c to 9dfeb2d Compare February 16, 2023 20:33
@chrisbobbe
Copy link
Contributor Author

chrisbobbe commented Feb 16, 2023

Thanks for the review! Revision pushed, and I also just sent #5663 for the compose box.

@gnprice
Copy link
Member

gnprice commented Feb 16, 2023

Thanks! Looks good; merging. I'll look at that other one next.

@gnprice gnprice force-pushed the pr-sharing-feedback-upload-fails branch from 9dfeb2d to 22129e9 Compare February 16, 2023 23:27
@gnprice gnprice merged commit 22129e9 into zulip:main Feb 16, 2023
@chrisbobbe chrisbobbe deleted the pr-sharing-feedback-upload-fails branch February 16, 2023 23:34
@chrisbobbe
Copy link
Contributor Author

Thanks!

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.

2 participants