ErrorCodeTooltip.utils.ts 881 B

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