Classes

@system-inc/base-foundation · 515c140 · 5 symbols

extends Error

View source ↗

An error type that represents an error during validation.

Accepts either the framework's runtime ValidationError (from foundation/validation) or its wire-form ValidationErrorData counterpart — both shape-compatible for simple pass-through.

extends BaseError

Members

  • cause?: BaseError

    The error that caused this error.

  • errorCode?: string

    Application-specific error code for programmatic error handling. Examples: 'DEVICE_ID_REQUIRED', 'AUTH.TOKEN_EXPIRED'

  • extensions: { validationErrors: readonly (Readonly<{ constraints: { [rule: string]: string }; path: string }>)[] }

    A dictionary of additional information for this error.

  • statusCode: HttpStatusCode

    The HTTP status code for this error.

  • validationErrors: readonly (Readonly<{ constraints: { [rule: string]: string }; path: string }>)[]

  • getSerializer(): BaseErrorSerializer

  • toJSON(): { cause?: { readonly name: string; readonly message: string; readonly statusCode: number; readonly stack?: string | undefined; readonly errorCode?: string | undefined; readonly cause?: ... | undefined; readonly extensions?: Readonly<...> | undefined; }; errorCode?: string; extensions?: Readonly<JsonObject>; message: string; name: string; stack?: string; statusCode: number }

    Serializes the error, with options for masking details.

  • toString(): string

    Returns a string representation of an object.

  • static forClient(error: unknown, defaultMessage: string): { masked: boolean; raw: unknown; safe: BaseError }

    Returns a client-safe BaseError. Authored 4xx errors pass through unchanged so their message, errorCode, and extensions reach the client. Anything else — plain Errors, 5xx BaseErrors, non-Error throws — is substituted with a generic 500 so internal details (V8 messages, stack traces, infrastructure errors) don't leak across the wire.

    Returns the original throw as raw so the caller can log it.

    Use this at transport boundaries (HTTP, RPC, GraphQL). For internal paths that need the unmasked error (task retry, alerting), use normalize instead.

  • static fromErrorData(data: { cause?: { readonly name: string; readonly message: string; readonly statusCode: number; readonly stack?: string | undefined; readonly errorCode?: string | undefined; readonly cause?: ... | undefined; readonly extensions?: Readonly<...> | undefined; }; errorCode?: string; extensions?: Readonly<JsonObject>; message: string; name: string; stack?: string; statusCode: number }): BaseError

    Creates a BaseError from error data.

  • static fromHttpStatus(statusCode: HttpStatusCode, options?: Omit<BaseErrorOptions, "statusCode">): BaseError

    Creates a BaseError from an HTTP status code.

  • static fromMessage(message: string, options?: BaseErrorOptions): BaseError

    Creates a BaseError from a message. Surfaces as a 500 error.

  • static normalize(error: unknown): BaseError

    Creates a new BaseError from an error. Surfaces as a 500 error if a status code was not specified in the originating error.

  • static wrap(fn: () => T, statusCode: HttpStatusCode): T

    Runs a function and rethrows any error it throws as a BaseError carrying the original message. Defaults to 422 (Unprocessable Entity); callers can pass a different status (e.g. 400 for malformed requests, 403 for policy rejection).

    Use at API boundaries (resolvers, RPC entry points) so that failures from utilities — which conventionally throw plain Error with a specific reason — surface as application-level errors with a meaningful status, instead of generic 500s.

View source ↗

Base error class for all errors in a Base application. Simply wraps the StatusError class from IttyRouter.

extends Error

Members

  • cause?: BaseError

    The error that caused this error.

  • errorCode?: string

    Application-specific error code for programmatic error handling. Examples: 'DEVICE_ID_REQUIRED', 'AUTH.TOKEN_EXPIRED'

  • extensions?: Readonly<JsonObject>

    A dictionary of additional information for this error.

  • statusCode: HttpStatusCode

    The HTTP status code for this error.

  • getSerializer(): BaseErrorSerializer

  • toJSON(): { cause?: { readonly name: string; readonly message: string; readonly statusCode: number; readonly stack?: string | undefined; readonly errorCode?: string | undefined; readonly cause?: ... | undefined; readonly extensions?: Readonly<...> | undefined; }; errorCode?: string; extensions?: Readonly<JsonObject>; message: string; name: string; stack?: string; statusCode: number }

    Serializes the error, with options for masking details.

  • toString(): string

    Returns a string representation of an object.

  • static forClient(error: unknown, defaultMessage: string): { masked: boolean; raw: unknown; safe: BaseError }

    Returns a client-safe BaseError. Authored 4xx errors pass through unchanged so their message, errorCode, and extensions reach the client. Anything else — plain Errors, 5xx BaseErrors, non-Error throws — is substituted with a generic 500 so internal details (V8 messages, stack traces, infrastructure errors) don't leak across the wire.

    Returns the original throw as raw so the caller can log it.

    Use this at transport boundaries (HTTP, RPC, GraphQL). For internal paths that need the unmasked error (task retry, alerting), use normalize instead.

  • static fromErrorData(data: { cause?: { readonly name: string; readonly message: string; readonly statusCode: number; readonly stack?: string | undefined; readonly errorCode?: string | undefined; readonly cause?: ... | undefined; readonly extensions?: Readonly<...> | undefined; }; errorCode?: string; extensions?: Readonly<JsonObject>; message: string; name: string; stack?: string; statusCode: number }): BaseError

    Creates a BaseError from error data.

  • static fromHttpStatus(statusCode: HttpStatusCode, options?: Omit<BaseErrorOptions, "statusCode">): BaseError

    Creates a BaseError from an HTTP status code.

  • static fromMessage(message: string, options?: BaseErrorOptions): BaseError

    Creates a BaseError from a message. Surfaces as a 500 error.

  • static normalize(error: unknown): BaseError

    Creates a new BaseError from an error. Surfaces as a 500 error if a status code was not specified in the originating error.

  • static wrap(fn: () => T, statusCode: HttpStatusCode): T

    Runs a function and rethrows any error it throws as a BaseError carrying the original message. Defaults to 422 (Unprocessable Entity); callers can pass a different status (e.g. 400 for malformed requests, 403 for policy rejection).

    Use at API boundaries (resolvers, RPC entry points) so that failures from utilities — which conventionally throw plain Error with a specific reason — surface as application-level errors with a meaningful status, instead of generic 500s.

View source ↗

Transforms between BaseError and IBaseError for ORM storage.

implements OrmValueTransformer<BaseErrorSerializer | null, BaseErrorDataType | null>

Members

  • mode: "client" | "debug"

  • from(value: { cause?: { readonly name: string; readonly message: string; readonly statusCode: number; readonly stack?: string | undefined; readonly errorCode?: string | undefined; readonly cause?: ... | undefined; readonly extensions?: Readonly<...> | undefined; }; errorCode?: string; extensions?: Readonly<JsonObject>; message: string; name: string; stack?: string; statusCode: number } | null): BaseErrorSerializer | null

    Transforms the value from the database to the entity property. Called during entity hydration.

  • to(value: BaseErrorSerializer | null): { cause?: { readonly name: string; readonly message: string; readonly statusCode: number; readonly stack?: string | undefined; readonly errorCode?: string | undefined; readonly cause?: ... | undefined; readonly extensions?: Readonly<...> | undefined; }; errorCode?: string; extensions?: Readonly<JsonObject>; message: string; name: string; stack?: string; statusCode: number } | null

    Transforms the value from the entity property to the database. Called during insert/update operations.

View source ↗

Class for Http error handling and creation.

Members

View source ↗

Classes • Documentation • Base