@owlmeans/error
v0.1.7
Published
Serializable error base class with type registration for cross-process error propagation.
Downloads
32
Readme
@owlmeans/error
Serializable error base class with type registration for cross-process error propagation.
Overview
ResilientErrorbase class survives JSON serialization/deserialization across service boundaries- Error class registry ensures custom error types are correctly reconstructed after transport
- Helpers for marshaling errors to strings and back
Installation
bun add @owlmeans/errorUsage
Define and register a custom error type:
import { ResilientError } from '@owlmeans/error'
export class ProjectResourceError extends ResilientError {
static typeName = 'viable-project:error'
constructor(message: string = 'error') {
super(`viable-project:${message}`)
this.type = ProjectResourceError.typeName
}
}
ResilientError.registerErrorClass(ProjectResourceError)Marshal errors across service boundaries:
import { marshalError, ResilientError } from '@owlmeans/error'
// Server side: serialize for transport
const serialized = marshalError(caughtError)
// Client side: reconstruct the typed error
const restored = ResilientError.ensure(receivedError)API
ResilientError
Base class for all OwlMeans errors.
static typeName: string— override in subclasses to identify the error typestatic registerErrorClass(cls)— register a subclass for automatic reconstruction from JSONstatic ensure(err, throwOnUnknown?)— convert any error toResilientErrorstatic marshal(err)— serialize an error to a transportableErrorobjecttype: string— error type identifier set in the constructor
marshalError(err): Error
Convenience: ensures the error is a ResilientError, then marshals it.
enuserError<T>(err): T
Ensures an unknown caught value is a ResilientError. Alias for ResilientError.ensure.
ValueOrError<T>
type ValueOrError<T> = T | ResilientErrorRelated Packages
@owlmeans/context— context and services that propagate errors through the app
