Update
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
const PASSTHROUGH_CODES = new Set([
|
||||
'INVALID_CREDENTIALS',
|
||||
'LOGIN_RATE_LIMITED',
|
||||
'GUEST_ACCESS_DISABLED',
|
||||
'GUEST_READ_ONLY',
|
||||
'GUEST_PROJECT_SCOPE_REQUIRED',
|
||||
])
|
||||
|
||||
export function formatAuthError(error: unknown, fallback: string): string {
|
||||
if (!(error instanceof Error)) return fallback
|
||||
|
||||
const code = (error as { code?: string }).code
|
||||
if (code && PASSTHROUGH_CODES.has(code)) return error.message
|
||||
|
||||
if (
|
||||
code === 'REQUEST_ERROR'
|
||||
|| code === 'INTERNAL_ERROR'
|
||||
|| code === 'SESSION_CREATION_FAILED'
|
||||
|| /request failed|failed to fetch|networkerror/i.test(error.message)
|
||||
) {
|
||||
return fallback
|
||||
}
|
||||
|
||||
return error.message || fallback
|
||||
}
|
||||
Reference in New Issue
Block a user