ErrorCodeTooltip.utils.ts32 lines · main
1import {
2 ERROR_CODE_DOCS_URLS,
3 ERROR_CODES,
4 HTTP_ERROR_CODES,
5 type ErrorCodeDefinition,
6 type ErrorCodeService,
7} from 'shared-data'
8
9import { Service } from '@/data/graphql/graphql'
10
11const SERVICE_MAP: Partial<Record<Service, ErrorCodeService>> = {
12 [Service.Auth]: 'auth',
13 [Service.Realtime]: 'realtime',
14}
15
16export interface ErrorCodeInfo {
17 definition: ErrorCodeDefinition | undefined
18 docsUrl: string | undefined
19}
20
21export function getErrorCodeInfo(errorCode: string, service: Service | undefined): ErrorCodeInfo {
22 const mappedService = service ? SERVICE_MAP[service] : undefined
23
24 const definition = mappedService
25 ? (ERROR_CODES[mappedService]?.[errorCode] ??
26 HTTP_ERROR_CODES[mappedService]?.[Number(errorCode)])
27 : undefined
28
29 const docsUrl = mappedService ? ERROR_CODE_DOCS_URLS[mappedService] : undefined
30
31 return { definition, docsUrl }
32}