Skip to content

Commit 764a436

Browse files
cursor[bot]cursoragentraymondjacobson
authored
Fix generic DM create failure on chat permission 403s (#14128)
## Summary - Handle `createChat` permission failures (`403`) by opening the inbox-unavailable modal instead of showing a generic "Failed to create chat" toast. - Refresh blockers, blockees, and chat permissions before opening the modal so the correct call-to-action (follow/unblock/learn more) is shown. - Keep existing generic error toast + sentry reporting behavior for non-`403` failures. ## Files Changed - `packages/common/src/store/pages/chat/sagas.ts` - Added `inboxUnavailableModalActions` usage in `doCreateChat` catch path. - Added conditional `403` handling for single-recipient DM creates. ## Validation - Could not run lint in this environment because `eslint` is not installed in the workspace runtime (`sh: eslint: not found`). - Verified patch via `git diff` and scoped logic review. <div><a href="https://cursor.com/agents/bc-da0e2204-854d-5c14-991a-9574848b3096"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/open-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/open-in-web-light.png"><img alt="Open in Web" width="114" height="28" src="https://cursor.com/assets/images/open-in-web-dark.png"></picture></a>&nbsp;<a href="https://cursor.com/automations/c63aa103-66df-4558-b31d-675358e5c6a1"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/view-automation-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/view-automation-light.png"><img alt="View Automation" width="141" height="28" src="https://cursor.com/assets/images/view-automation-dark.png"></picture></a>&nbsp;</div> Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Ray Jacobson <raymondjacobson@users.noreply.github.com>
1 parent 4ceefa4 commit 764a436

1 file changed

Lines changed: 24 additions & 7 deletions

File tree

  • packages/common/src/store/pages/chat

packages/common/src/store/pages/chat/sagas.ts

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { Feature } from '~/models/ErrorReporting'
3030
import { ID } from '~/models/Identifiers'
3131
import { Status } from '~/models/Status'
3232
import * as toastActions from '~/store/ui/toast/slice'
33+
import { inboxUnavailableModalActions } from '~/store/ui/modals'
3334
import dayjs from '~/utils/dayjs'
3435

3536
import {
@@ -93,6 +94,7 @@ const {
9394
const { getChatsSummary, getChat, getUnfurlMetadata, getNonOptimisticChat } =
9495
chatSelectors
9596
const { toast } = toastActions
97+
const { open: openInboxUnavailableModal } = inboxUnavailableModalActions
9698

9799
const CHAT_PAGE_SIZE = 30
98100
const MESSAGES_PAGE_SIZE = 50
@@ -433,14 +435,29 @@ function* doCreateChat(action: ReturnType<typeof createChat>) {
433435
yield* call(track, make({ eventName: Name.CREATE_CHAT_SUCCESS }))
434436
}
435437
} catch (e) {
436-
yield* put(
437-
toast({
438-
type: 'error',
439-
content: 'Something went wrong. Failed to create chat.'
440-
})
441-
)
438+
const isForbiddenError = isResponseError(e) && e.response?.status === 403
439+
if (isForbiddenError && userIds.length === 1) {
440+
// Refresh chat permissions and block state so InboxUnavailable can show
441+
// the right next action for the target user.
442+
yield* put(fetchBlockees())
443+
yield* put(fetchBlockers())
444+
yield* put(fetchPermissions({ userIds }))
445+
yield* put(
446+
openInboxUnavailableModal({
447+
userId: userIds[0],
448+
presetMessage
449+
})
450+
)
451+
} else {
452+
yield* put(
453+
toast({
454+
type: 'error',
455+
content: 'Something went wrong. Failed to create chat.'
456+
})
457+
)
458+
}
442459
const reportToSentry = yield* getContext('reportToSentry')
443-
if (!isResponseError(e) || e.response?.status !== 403) {
460+
if (!isForbiddenError) {
444461
reportToSentry({
445462
name: 'Chats',
446463
error: e as Error,

0 commit comments

Comments
 (0)