Home / Class/ ErrorModel Class — supabase Architecture

ErrorModel Class — supabase Architecture

Architecture documentation for the ErrorModel class in errorModel.ts from the supabase codebase.

Entity Profile

Relationship Graph

Source Code

apps/docs/resources/error/errorModel.ts lines 30–133

export class ErrorModel {
  public id: string
  public code: string
  public service: Service
  public httpStatusCode?: number
  public message?: string

  constructor({
    id,
    code,
    service,
    httpStatusCode,
    message,
  }: {
    id: string
    code: string
    service: Service
    httpStatusCode?: number
    message?: string
  }) {
    this.id = id
    this.code = code
    this.service = service
    this.httpStatusCode = httpStatusCode
    this.message = message
  }

  static async loadSingleError({
    code,
    service,
  }: {
    code: string
    service: Service
  }): Promise<Result<ErrorModel, ApiErrorGeneric>> {
    return new Result(
      await supabase()
        .schema('content')
        .from('error')
        .select('id, code, service(name), httpStatusCode:http_status_code, message')
        .eq('code', code)
        .eq('service.name', service)
        .is('deleted_at', null)
        .single<{
          id: string
          code: string
          service: {
            name: Service
          }
          httpStatusCode?: number
          message?: string
        }>()
    )
      .map((data) => {
        return new ErrorModel({
          ...data,
          service: data.service.name,
        })
      })
      .mapError((error) => {
        if (error.code === 'PGRST116') {
          return new NoDataError('Error for given code and service does not exist', error)
        }
        return convertPostgrestToApiError(error)
      })
  }

  static async loadErrors(
    args: Parameters<ErrorCollectionFetch>[0]
  ): ReturnType<ErrorCollectionFetch> {
    const PAGE_SIZE = 20
    const limit = args?.first ?? args?.last ?? PAGE_SIZE
    const service = args?.additionalArgs?.service as Service | undefined
    const code = args?.additionalArgs?.code as string | undefined

    const [countResult, errorCodesResult] = await Promise.all([
      fetchTotalErrorCount(service, code),
      fetchErrorDescriptions({
        after: args?.after ?? undefined,
        before: args?.before ?? undefined,
        reverse: !!args?.last,
        limit: limit + 1,
        service,
        code,
      }),
    ])

    return countResult
      .join(errorCodesResult)
      .map(([count, errorCodes]) => {
        const hasMoreItems = errorCodes.length > limit
        const items = args?.last ? errorCodes.slice(1) : errorCodes.slice(0, limit)

        return {
          items: items.map((errorCode) => new ErrorModel(errorCode)),
          totalCount: count,
          hasNextPage: args?.last ? !!args?.before : hasMoreItems,
          hasPreviousPage: args?.last ? hasMoreItems : !!args?.after,
        }
      })
      .mapError(([countError, errorCodeError]) => {
        return CollectionQueryError.fromErrors(countError, errorCodeError)
      })
  }
}

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free