Classes
@system-inc/base-foundation · 515c140 · 5 symbols
AbortedError
extends Error
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?:BaseErrorThe error that caused this error.
errorCode?:stringApplication-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:HttpStatusCodeThe HTTP status code for this error.
validationErrors:readonly (Readonly<{ constraints: { [rule: string]: string }; path: string }>)[]getSerializer():BaseErrorSerializertoJSON():{ 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():stringReturns 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
rawso 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 }):BaseErrorCreates a BaseError from error data.
static fromHttpStatus(statusCode:HttpStatusCode,options?:Omit<BaseErrorOptions, "statusCode">):BaseErrorCreates a BaseError from an HTTP status code.
static fromMessage(message:string,options?:BaseErrorOptions):BaseErrorCreates a BaseError from a message. Surfaces as a 500 error.
static normalize(error:unknown):BaseErrorCreates 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):TRuns 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
Errorwith a specific reason — surface as application-level errors with a meaningful status, instead of generic 500s.
BaseError
Base error class for all errors in a Base application. Simply wraps the StatusError class from IttyRouter.
extends Error
Members
cause?:BaseErrorThe error that caused this error.
errorCode?:stringApplication-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:HttpStatusCodeThe HTTP status code for this error.
getSerializer():BaseErrorSerializertoJSON():{ 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():stringReturns 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
rawso 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 }):BaseErrorCreates a BaseError from error data.
static fromHttpStatus(statusCode:HttpStatusCode,options?:Omit<BaseErrorOptions, "statusCode">):BaseErrorCreates a BaseError from an HTTP status code.
static fromMessage(message:string,options?:BaseErrorOptions):BaseErrorCreates a BaseError from a message. Surfaces as a 500 error.
static normalize(error:unknown):BaseErrorCreates 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):TRuns 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
Errorwith a specific reason — surface as application-level errors with a meaningful status, instead of generic 500s.
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 | nullTransforms 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 } | nullTransforms the value from the entity property to the database. Called during insert/update operations.
HttpErrors
Class for Http error handling and creation.
Members
static badRequest(options?:HttpErrorOptions):BaseErrorCreates StatusError: 400 Bad Request
static conflict(options?:HttpErrorOptions):BaseErrorCreates StatusError: 409 Conflict
static forbidden(options?:HttpErrorOptions):BaseErrorCreates StatusError: 403 Forbidden
static internalServerError(options?:HttpErrorOptions):BaseErrorCreates StatusError: 500 Internal Server Error
static methodNotAllowed(options?:HttpErrorOptions):BaseErrorCreates StatusError: 405 Method Not Allowed
static notFound(options?:HttpErrorOptions):BaseErrorCreates StatusError: 404 Not Found
static notImplemented(options?:HttpErrorOptions):BaseErrorCreates StatusError: 501 Not Implemented
static serviceUnavailable(options?:HttpErrorOptions):BaseErrorCreates StatusError: 503 Service Unavailable
static statusError(statusCode:HttpStatusCode,options?:HttpErrorOptions):BaseErrorCreates a status error for any HTTP status code.
static unauthorized(options?:HttpErrorOptions):BaseErrorCreates StatusError: 401 Unauthorized
static unprocessableEntity(options?:HttpErrorOptions):BaseErrorCreates StatusError: 422 Unprocessable Entity
static upgradeRequired(options?:HttpErrorOptions):BaseErrorCreates StatusError: 426 Upgrade Required