ResultError
The library normalizes unknown values to aResultError with:
code: stable identifiermessage: error descriptionstatus?: optional numeric statusmeta?: additional payloadcause?: original value
Default normalizer
If no custom rules are provided,trybox automatically applies the following rules:
- abort: Detects
AbortErrorand returnscode: "ABORTED". - timeout: Detects
TimeoutErrorand returnscode: "TIMEOUT". - httpStatus: Detects errors with numeric
statusorstatusCode. Returnscode: "HTTP"and preserves the status. - aggregate: Handles
AggregateErrorby saving internal errors inmeta.errors. - string: If a string is thrown, it is used as the message.
- message: Extracts the
messageproperty from objects.
Custom rules
UseerrorRule to define specific mappings and trybox to apply them.
Transformation with mapError
Allows adjusting the already normalized error to enrich or standardize it.
Cancellation and Timeout
signalandtimeoutaffect how long we wait for the task to complete.- If your function does not consume the provided
AbortSignal, the library cannot cancel underlying I/O automatically. - We race the task and return
ABORTED/TIMEOUTpromptly, but the inner request only stops if it cooperates withsignal.
Circuit Breaker (Runner-level)
- Circuit breaker is configured at the Runner level:
trybox({ circuitBreaker }). - Per-call circuit breaker is intentionally not exposed in
RunOptionsto keep the API lean.