import { SENDABLE_ERROR_INSTANCE_SYMBOL } from "./Consts.js"; import { type BaseErrorCode } from "./ErrorCode.js"; import type { ErrorResponseBody, ResponseWithError } from "./Types.js"; export interface LogOptions { message?: string; source?: string; info?: any; } export interface ErrorResponse extends Response { cause?: SendableError | Error; } /** * Transforms an error into a deterministic error identifier to enable easy log searching */ export declare const getTraceId: (error: Error) => string; export type SendableErrorDetails = Record; export interface PublicProperties { enabled: boolean; code?: BaseErrorCode; message?: string; } type PublicOptions = Omit & { code?: BaseErrorCode | string; }; export type DefaultSendableErrorDetails = Record; export interface SendableErrorProperties { code: BaseErrorCode; message: string; public?: PublicProperties; details?: D & Record; cause?: unknown; status?: number; } export interface SendableErrorOptions extends Omit, "code" | "message" | "public"> { code?: BaseErrorCode | string; message?: string; public?: boolean | PublicOptions; } export interface SendableErrorState { logged: boolean; traceId: string; } export interface ToResponseBodyOptions { defaultPublic?: boolean | PublicProperties; public?: boolean | PublicProperties; details?: SendableErrorDetails; } /** * An error with a known cause that is sendable */ export default class SendableError extends Error { private [SENDABLE_ERROR_INSTANCE_SYMBOL]; private properties; private state; static is(error: any): error is SendableError; static of(error: Error, options?: Partial>): SendableError; constructor(options?: SendableErrorOptions); private overrideProperty; private init; getStack(): string | undefined; getCause(): unknown | undefined; getCode(): BaseErrorCode; getMessage(): string; isPublic(): boolean; toResponse(options?: ToResponseBodyOptions): ErrorResponse; toResponseBody(options?: ToResponseBodyOptions): ErrorResponseBody; getStatus(): number; getDetails(): SendableErrorDetails | undefined; get details(): SendableErrorDetails | undefined; getTraceId(): string; /** * Sends the error (if a response wasn't already sent) & logs if it wasn't already logged */ send(res: ResponseWithError, options?: ToResponseBodyOptions): this; logIfUnlogged(options?: LogOptions): void; /** * Log out info on error */ log(options?: LogOptions): this; } export {};