mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 23:49:03 +00:00
## What
Moves the `ResponseError` class (`types/base.ts`) and the classified
error classes (`types/api-errors.ts`) into
`lib/errors/studio-errors.ts`, and renames `ResponseError` to
`StudioError`.
## Why
Studio's error classification is being expanded to cover errors that
don't come from API responses (thrown network failures, aborted
requests, unexpected client errors). The API-specific name and location
no longer fit. Landing the rename on its own keeps the follow-up PR,
which introduces the classified error model, small and reviewable.
## Notes for reviewers
- Mechanical change, no behavior change. Most of the diff is a one-line
import change per file plus import re-sorting by Prettier.
- Files that only use the type now use `import type { StudioError }`.
- `ResponseError` is no longer re-exported from `@/types`; there are no
compatibility shims at the old paths.
- Unrelated identifiers like `QueryResponseError` and
`parseResponseErrors` are unchanged.
104 lines
2.8 KiB
TypeScript
104 lines
2.8 KiB
TypeScript
import type { OrganizationInviteByToken } from '@/data/organization-members/organization-invitation-token-query'
|
|
import type { StudioError } from '@/lib/errors/studio-errors'
|
|
|
|
type OrganizationInviteStatusVariables = {
|
|
data?: OrganizationInviteByToken
|
|
error?: StudioError | null
|
|
isErrorInvitation: boolean
|
|
isLoadingInvitation: boolean
|
|
isLoadingProfile: boolean
|
|
isLoggedIn: boolean
|
|
isRouterReady: boolean
|
|
isSuccessInvitation: boolean
|
|
profileExists: boolean
|
|
}
|
|
|
|
export type OrganizationInviteStatus =
|
|
| 'signed-out'
|
|
| 'loading'
|
|
| 'ready'
|
|
| 'wrong-account'
|
|
| 'expired'
|
|
| 'invalid'
|
|
| 'no-longer-valid'
|
|
| 'error'
|
|
|
|
export function getOrganizationInviteStatus({
|
|
data,
|
|
error,
|
|
isErrorInvitation,
|
|
isLoadingInvitation,
|
|
isLoadingProfile,
|
|
isLoggedIn,
|
|
isRouterReady,
|
|
isSuccessInvitation,
|
|
profileExists,
|
|
}: OrganizationInviteStatusVariables): OrganizationInviteStatus {
|
|
const isSignedOut = !isLoggedIn || (!profileExists && !isLoadingProfile)
|
|
|
|
if (isSignedOut) return 'signed-out'
|
|
if (isLoadingProfile || isLoadingInvitation || !isRouterReady) return 'loading'
|
|
|
|
if (error?.code === 401 && error?.message.includes('Failed to retrieve organization')) {
|
|
return 'no-longer-valid'
|
|
}
|
|
|
|
if (
|
|
(isSuccessInvitation && !!data?.token_does_not_exist) ||
|
|
(isErrorInvitation && error?.code === 404)
|
|
) {
|
|
return 'invalid'
|
|
}
|
|
|
|
if (isErrorInvitation) return 'error'
|
|
if (isSuccessInvitation && !!data?.expired_token) return 'expired'
|
|
if (isSuccessInvitation && !!data && !data.email_match) return 'wrong-account'
|
|
|
|
return 'ready'
|
|
}
|
|
|
|
export function getOrganizationInviteContent({
|
|
data,
|
|
error,
|
|
isSignUpEnabled,
|
|
status,
|
|
}: {
|
|
data?: OrganizationInviteByToken
|
|
error?: StudioError | null
|
|
isSignUpEnabled: boolean
|
|
status: OrganizationInviteStatus
|
|
}) {
|
|
const signedOutDescription = `Sign in${
|
|
isSignUpEnabled ? ' or create an account' : ''
|
|
} to view this invitation`
|
|
|
|
if (status === 'signed-out') {
|
|
return {
|
|
title: 'View invitation',
|
|
description: signedOutDescription,
|
|
}
|
|
}
|
|
|
|
if (status === 'ready') {
|
|
return {
|
|
title: `Join ${data?.organization_name ?? 'an organization'}`,
|
|
description: 'You have been invited to join this Supabase organization',
|
|
}
|
|
}
|
|
|
|
if (status === 'wrong-account') return { title: 'Wrong account' }
|
|
if (status === 'expired') return { title: 'Invite expired' }
|
|
if (status === 'invalid') return { title: 'Invalid invitation' }
|
|
if (status === 'no-longer-valid') return { title: 'Invite no longer available' }
|
|
if (status === 'error') {
|
|
if (error?.message.includes('MFA required')) {
|
|
return {
|
|
title: 'Set up MFA for your account',
|
|
description: 'MFA needs to be enabled on your account to join this organization',
|
|
}
|
|
} else return { title: 'Unable to load invitation' }
|
|
}
|
|
|
|
return {}
|
|
}
|