dify/web/app/components/header/account-setting/members-page/invite-modal/invite-error.ts
yyh 509a8b1452
fix: align member invitation state and errors (#38885)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2026-07-14 03:05:44 +00:00

25 lines
808 B
TypeScript

import type { MemberInviteErrorResponse } from '@dify/contracts/api/console/workspaces/types.gen'
type InviteErrorCode = MemberInviteErrorResponse['code']
const INVITE_ERROR_CODES = new Set<InviteErrorCode>([
'invalid_param',
'invalid_role',
'limit_exceeded',
])
function getRecord(value: unknown) {
return typeof value === 'object' && value !== null ? (value as Record<string, unknown>) : null
}
export function getInviteErrorCode(error: unknown): InviteErrorCode | null {
const errorRecord = getRecord(error)
const dataRecord = getRecord(errorRecord?.data)
const bodyRecord = getRecord(dataRecord?.body)
const code = bodyRecord?.code ?? errorRecord?.code
return typeof code === 'string' && INVITE_ERROR_CODES.has(code as InviteErrorCode)
? (code as InviteErrorCode)
: null
}