|
3 | 3 | import parseMarkdown from 'zulip-markdown-parser';
|
4 | 4 | import invariant from 'invariant';
|
5 | 5 |
|
| 6 | +import { ApiError } from '../api/apiErrors'; |
| 7 | +import { showErrorAlert } from '../utils/info'; |
6 | 8 | import * as logging from '../utils/logging';
|
7 | 9 | import type {
|
8 | 10 | PerAccountState,
|
@@ -79,14 +81,30 @@ const trySendMessages = (dispatch, getState): boolean => {
|
79 | 81 | // CSV, then a literal. To avoid misparsing, always use JSON.
|
80 | 82 | : JSON.stringify([streamNameOfStreamMessage(item)]);
|
81 | 83 |
|
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 | + } |
90 | 108 | dispatch(messageSendComplete(item.timestamp));
|
91 | 109 | });
|
92 | 110 | return true;
|
|
0 commit comments