Skip to content

Commit

Permalink
outboxActions: Show dialog if message send fails with informative Api…
Browse files Browse the repository at this point in the history
…Error

This is our minimal support for zulip#5870 in this legacy codebase.
Supporting it properly with a client-side check of the setting is
more effort than we can spare right now.

Probably more error handling is called for, but zulip#3881 ("Sending
outbox messages is fraught with issues") is complicated and it's
probably best to leave it be.

Fixes: zulip#5870
  • Loading branch information
chrisbobbe committed Jul 10, 2024
1 parent e352f56 commit 072ad6b
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions src/outbox/outboxActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import parseMarkdown from 'zulip-markdown-parser';
import invariant from 'invariant';

import { ApiError } from '../api/apiErrors';
import { showErrorAlert } from '../utils/info';
import * as logging from '../utils/logging';
import type {
PerAccountState,
Expand Down Expand Up @@ -79,14 +81,30 @@ const trySendMessages = (dispatch, getState): boolean => {
// CSV, then a literal. To avoid misparsing, always use JSON.
: JSON.stringify([streamNameOfStreamMessage(item)]);

await api.sendMessage(auth, {
type: item.type,
to,
subject: item.subject,
content: item.markdownContent,
localId: item.timestamp,
eventQueueId: state.session.eventQueueId ?? undefined,
});
try {
await api.sendMessage(auth, {
type: item.type,
to,
subject: item.subject,
content: item.markdownContent,
localId: item.timestamp,
eventQueueId: state.session.eventQueueId ?? undefined,
});
} catch (errorIllTyped) {
const error: mixed = errorIllTyped; // https://github.com/facebook/flow/issues/2470

if (error instanceof ApiError && error.message.length > 0) {
showErrorAlert(
// TODO(i18n) nontrivial to plumb through GetText;
// skip for now in this legacy codebase
'Failed to send message',
// E.g., "You do not have permission to send direct messages to this recipient."
`The server at ${auth.realm.toString()} said:\n\n${error.message}`,
);
dispatch(deleteOutboxMessage(item.id));
return;
}
}
dispatch(messageSendComplete(item.timestamp));
});
return true;
Expand Down

0 comments on commit 072ad6b

Please sign in to comment.