Error class for service-level errors, convertible to JSON:API errors.

Hierarchy

  • Error
    • ServiceError

Constructors

Properties

cause?: unknown
id: string
issues: readonly Issue[]
message: string
name: string
source: ErrorSource
stack?: string
status: 400 | 401 | 403 | 404 | 409 | 422 | 429 | 500
prepareStackTrace?: (err: Error, stackTraces: CallSite[]) => any

Optional override for formatting stack traces

stackTraceLimit: number

Methods

  • Converts the error to JSON:API format

    Returns {
        errors: {
            code: ErrorCode;
            detail?: string;
            id: string;
            source?: { [key: string]: string };
            status: string;
            title: string;
        }[];
    }

    Object conforming to JSON:API error format

  • Create .stack property on a target object

    Parameters

    • targetObject: object
    • OptionalconstructorOpt: Function

    Returns void

  • Converts an unknown value to a ServiceError. Typically called from catch blocks.

    Parameters

    • value: unknown

      The value to convert, which can be any type

    Returns ServiceError

    If the value is already a ServiceError, returns it unchanged. Otherwise, convert it to a ServiceError.