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

ComposeBox: Show more information on file-upload errors #5663

Merged
merged 2 commits into from
Feb 16, 2023
Merged
Changes from all commits
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
26 changes: 23 additions & 3 deletions src/compose/ComposeBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { TranslationContext } from '../boot/TranslationProvider';
import { draftUpdate, sendTypingStart, sendTypingStop } from '../actions';
import Touchable from '../common/Touchable';
import Input from '../common/Input';
import { showToast, showErrorAlert } from '../utils/info';
import { showErrorAlert } from '../utils/info';
import { IconDone, IconSend } from '../common/Icons';
import {
isConversationNarrow,
Expand Down Expand Up @@ -73,6 +73,7 @@ import { tryFetch } from '../message/fetchActions';
import { getMessageUrl } from '../utils/internalLinks';
import * as logging from '../utils/logging';
import type { Attachment } from './ComposeMenu';
import { ApiError, RequestError } from '../api/apiErrors';

/* eslint-disable no-shadow */

Expand Down Expand Up @@ -339,8 +340,27 @@ const ComposeBox: React$AbstractComponent<Props, ImperativeHandle> = forwardRef(
let response = null;
try {
response = await api.uploadFile(auth, attachments[i].url, fileName);
} catch {
showToast(_('Failed to upload file: {fileName}', { fileName }));
} catch (errorIllTyped) {
const error: mixed = errorIllTyped; // https://github.com/facebook/flow/issues/2470

if (!(error instanceof Error)) {
logging.error('ComposeBox: Unexpected non-error thrown');
}

let msg = undefined;
if (
error instanceof RequestError
&& error.httpStatus === 413 // 413 Payload Too Large:
// https://github.com/zulip/zulip-mobile/issues/5148#issuecomment-1092140960
) {
msg = _('The server said the file is too large.');
} else if (error instanceof ApiError) {
msg = _('The server said:\n\n{errorMessage}', { errorMessage: error.message });
} else if (error instanceof Error && error.message.length > 0) {
msg = error.message;
}
showErrorAlert(_('Failed to upload file: {fileName}', { fileName }), msg);

setMessageInputValue(state =>
state.value.replace(
placeholder,
Expand Down