classify migrated chat group errors with matchXrpcError

The lex client throws XrpcResponseError, which is not an XRPCError
subclass, so the per-method error classes generated by @atproto/api no
longer match. Those instanceof checks compile fine but silently stop
firing, degrading every typed group failure to the generic fallback
message. Narrow against the method schema instead.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Samuel Newman
2026-08-03 16:30:01 +03:00
parent 74f4532922
commit 72162c1544
6 changed files with 116 additions and 123 deletions
+21 -24
View File
@@ -1,5 +1,4 @@
import {useCallback} from 'react'
import {ChatBskyGroupCreateGroup} from '@atproto/api'
import {Trans, useLingui} from '@lingui/react/macro'
import {useRequireEmailVerification} from '#/lib/hooks/useRequireEmailVerification'
@@ -88,29 +87,27 @@ export function NewChat({
let errorMessage = l`An issue occurred starting the group chat, please try again.`
if (isNetworkError(error)) {
errorMessage = l`A network error occurred. Please check your internet connection.`
} else if (
error instanceof ChatBskyGroupCreateGroup.AccountSuspendedError
) {
errorMessage = l`Suspended accounts cannot participate in a group chat.`
} else if (error instanceof ChatBskyGroupCreateGroup.BlockedActorError) {
errorMessage = l`One of the selected recipients has blocked you and cannot be messaged.`
} else if (
error instanceof
ChatBskyGroupCreateGroup.NewAccountCannotCreateGroupError
) {
errorMessage = l`You cannot create a group chat yet.`
} else if (
error instanceof ChatBskyGroupCreateGroup.NotFollowedBySenderError
) {
errorMessage = l`A selected recipient is not followed by the sender.`
} else if (
error instanceof ChatBskyGroupCreateGroup.RecipientNotFoundError
) {
errorMessage = l`Unable to find a selected recipient.`
} else if (
error instanceof ChatBskyGroupCreateGroup.UserForbidsGroupsError
) {
errorMessage = l`One of the selected recipients does not allow group chats.`
} else {
switch (matchXrpcError(error, chat.bsky.group.createGroup)) {
case 'AccountSuspended':
errorMessage = l`Suspended accounts cannot participate in a group chat.`
break
case 'BlockedActor':
errorMessage = l`One of the selected recipients has blocked you and cannot be messaged.`
break
case 'NewAccountCannotCreateGroup':
errorMessage = l`You cannot create a group chat yet.`
break
case 'NotFollowedBySender':
errorMessage = l`A selected recipient is not followed by the sender.`
break
case 'RecipientNotFound':
errorMessage = l`Unable to find a selected recipient.`
break
case 'UserForbidsGroups':
errorMessage = l`One of the selected recipients does not allow group chats.`
break
}
}
Toast.show(errorMessage, {
type: 'error',
@@ -1,5 +1,4 @@
import {useCallback, useState} from 'react'
import {ChatBskyGroupCreateGroup} from '@atproto/api'
import {useLingui} from '@lingui/react/macro'
import {isNetworkError} from '#/lib/strings/errors'
@@ -104,29 +103,27 @@ function SendViaChatDialogInner({
let errorMessage = l`An issue occurred starting the group chat, please try again.`
if (isNetworkError(error)) {
errorMessage = l`A network error occurred. Please check your internet connection.`
} else if (
error instanceof ChatBskyGroupCreateGroup.AccountSuspendedError
) {
errorMessage = l`Suspended accounts cannot participate in a group chat.`
} else if (error instanceof ChatBskyGroupCreateGroup.BlockedActorError) {
errorMessage = l`One of the selected recipients has blocked you and cannot be messaged.`
} else if (
error instanceof
ChatBskyGroupCreateGroup.NewAccountCannotCreateGroupError
) {
errorMessage = l`You cannot create a group chat yet.`
} else if (
error instanceof ChatBskyGroupCreateGroup.NotFollowedBySenderError
) {
errorMessage = l`A selected recipient is not followed by the sender.`
} else if (
error instanceof ChatBskyGroupCreateGroup.RecipientNotFoundError
) {
errorMessage = l`Unable to find a selected recipient.`
} else if (
error instanceof ChatBskyGroupCreateGroup.UserForbidsGroupsError
) {
errorMessage = l`One of the selected recipients does not allow group chats.`
} else {
switch (matchXrpcError(error, chat.bsky.group.createGroup)) {
case 'AccountSuspended':
errorMessage = l`Suspended accounts cannot participate in a group chat.`
break
case 'BlockedActor':
errorMessage = l`One of the selected recipients has blocked you and cannot be messaged.`
break
case 'NewAccountCannotCreateGroup':
errorMessage = l`You cannot create a group chat yet.`
break
case 'NotFollowedBySender':
errorMessage = l`A selected recipient is not followed by the sender.`
break
case 'RecipientNotFound':
errorMessage = l`Unable to find a selected recipient.`
break
case 'UserForbidsGroups':
errorMessage = l`One of the selected recipients does not allow group chats.`
break
}
}
Toast.show(errorMessage, {
type: 'error',