Skip to content

Commit 2ae8d8e

Browse files
chrisbobbegnprice
authored andcommitted
outboxActions: Show dialog if message send fails with informative ApiError
This is our minimal support for #5870 in this legacy codebase. Supporting it properly with a client-side check of the setting is more effort than we can spare here, because it requires implementing the group-based permissions system. Probably more error handling is called for in general (like for network or server issues), but #3881 ("Sending outbox messages is fraught with issues") is complicated and it's probably best to leave it be. Fixes: #5870
1 parent 966e7f3 commit 2ae8d8e

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

src/outbox/outboxActions.js

+26-8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import parseMarkdown from 'zulip-markdown-parser';
44
import invariant from 'invariant';
55

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

82-
await api.sendMessage(auth, {
83-
type: item.type,
84-
to,
85-
subject: item.subject,
86-
content: item.markdownContent,
87-
localId: item.timestamp,
88-
eventQueueId: state.session.eventQueueId ?? undefined,
89-
});
84+
try {
85+
await api.sendMessage(auth, {
86+
type: item.type,
87+
to,
88+
subject: item.subject,
89+
content: item.markdownContent,
90+
localId: item.timestamp,
91+
eventQueueId: state.session.eventQueueId ?? undefined,
92+
});
93+
} catch (errorIllTyped) {
94+
const error: mixed = errorIllTyped; // https://github.com/facebook/flow/issues/2470
95+
96+
if (error instanceof ApiError && error.message.length > 0) {
97+
showErrorAlert(
98+
// TODO(i18n) nontrivial to plumb through GetText;
99+
// skip for now in this legacy codebase
100+
'Failed to send message',
101+
// E.g., "You do not have permission to send direct messages to this recipient."
102+
`The server at ${auth.realm.toString()} said:\n\n${error.message}`,
103+
);
104+
dispatch(deleteOutboxMessage(item.id));
105+
return;
106+
}
107+
}
90108
dispatch(messageSendComplete(item.timestamp));
91109
});
92110
return true;

0 commit comments

Comments
 (0)