execute() throws, and a catch (e) gives you unknown. The builder already knows which errors its strategies can
raise: a timeout raises TIMEOUT, a circuit breaker CIRCUIT_OPEN and CIRCUIT_ISOLATED. settle() returns them as
a typed outcome instead of throwing, and Outcome.match() makes you handle each one.
Polly-style builder with a shortcut for every strategy: addRetry(), addTimeout(), addCircuitBreaker(), …
Convenient, but it bundles every strategy. For the smallest browser bundle use PipelineBuilder with
retryStrategy(), timeoutStrategy(), … instead; the two are interchangeable.
The type parameters track which errors the pipeline can raise, for pipeline.settle() + Outcome.match().
match<T, E, HextendsOutcomeHandlers<T, E, unknown>>(outcome:Outcome<T, E>, handlers:H):ReturnType<H[keyofH] & ((...args:any) =>any)>;
}
The result of an execution: either a value or an error. Strategies pass outcomes around instead of throwing.
E is the error type when it's known (see pipeline.settle()), unknown otherwise.
Polly-style builder with a shortcut for every strategy: addRetry(), addTimeout(), addCircuitBreaker(), …
Convenient, but it bundles every strategy. For the smallest browser bundle use PipelineBuilder with
retryStrategy(), timeoutStrategy(), … instead; the two are interchangeable.
The type parameters track which errors the pipeline can raise, for pipeline.settle() + Outcome.match().
Like executeOutcome, but the error is typed: the errors this pipeline's strategies can raise (E), the errors your
callback returns with Outcome.fromError(…) (E2), or UnexpectedError wrapping anything else (a thrown bug, a
client error). Pair it with Outcome.match() for exhaustive handling:
constoutcome=await pipeline.settle(async () => (user ? user : Outcome.fromError(newNotFound(id))));
match<T, E, HextendsOutcomeHandlers<T, E, unknown>>(outcome:Outcome<T, E>, handlers:H):ReturnType<H[keyofH] & ((...args:any) =>any)>;
}
The result of an execution: either a value or an error. Strategies pass outcomes around instead of throwing.
E is the error type when it's known (see pipeline.settle()), unknown otherwise.
match<T, E, HextendsOutcomeHandlers<T, E, unknown>>(outcome:Outcome<T, E>, handlers:H):ReturnType<H[keyofH] & ((...args:any) =>any)>;
}
The result of an execution: either a value or an error. Strategies pass outcomes around instead of throwing.
E is the error type when it's known (see pipeline.settle()), unknown otherwise.
Errors the callback returns with Outcome.fromError(…)
NotFound
your code
Anything else, wrapped
a thrown bug, a 4xx, a driver error
UNEXPECTED (UnexpectedError, original in .cause)
Outcome.match needs a handler for ok and for every code in the union. Forget one and the call doesn’t compile.
At runtime it dispatches on error.code.
Returned errors are still failures. Strategies see them like thrown errors, so they can be retried or counted by
the breaker (subject to shouldHandle).
Opt-in.execute() and executeOutcome() don’t change.
Give your own errors a literal code (readonly code = 'NOT_FOUND' as const); that is what match keys on.
Polly-style builder with a shortcut for every strategy: addRetry(), addTimeout(), addCircuitBreaker(), …
Convenient, but it bundles every strategy. For the smallest browser bundle use PipelineBuilder with
retryStrategy(), timeoutStrategy(), … instead; the two are interchangeable.
The type parameters track which errors the pipeline can raise, for pipeline.settle() + Outcome.match().
Polly-style builder with a shortcut for every strategy: addRetry(), addTimeout(), addCircuitBreaker(), …
Convenient, but it bundles every strategy. For the smallest browser bundle use PipelineBuilder with
retryStrategy(), timeoutStrategy(), … instead; the two are interchangeable.
The type parameters track which errors the pipeline can raise, for pipeline.settle() + Outcome.match().
Polly-style builder with a shortcut for every strategy: addRetry(), addTimeout(), addCircuitBreaker(), …
Convenient, but it bundles every strategy. For the smallest browser bundle use PipelineBuilder with
retryStrategy(), timeoutStrategy(), … instead; the two are interchangeable.
The type parameters track which errors the pipeline can raise, for pipeline.settle() + Outcome.match().
Like executeOutcome, but the error is typed: the errors this pipeline's strategies can raise (E), the errors your
callback returns with Outcome.fromError(…) (E2), or UnexpectedError wrapping anything else (a thrown bug, a
client error). Pair it with Outcome.match() for exhaustive handling:
constoutcome=await pipeline.settle(async () => (user ? user : Outcome.fromError(newNotFound(id))));
match<T, E, HextendsOutcomeHandlers<T, E, unknown>>(outcome:Outcome<T, E>, handlers:H):ReturnType<H[keyofH] & ((...args:any) =>any)>;
}
The result of an execution: either a value or an error. Strategies pass outcomes around instead of throwing.
E is the error type when it's known (see pipeline.settle()), unknown otherwise.
Polly-style builder with a shortcut for every strategy: addRetry(), addTimeout(), addCircuitBreaker(), …
Convenient, but it bundles every strategy. For the smallest browser bundle use PipelineBuilder with
retryStrategy(), timeoutStrategy(), … instead; the two are interchangeable.
The type parameters track which errors the pipeline can raise, for pipeline.settle() + Outcome.match().
ResiliencePipeline<any, WithErrors<TimeoutRejectedError, never, BulkheadRejectedError>>.isError(error: unknown): error is WithErrors<TimeoutRejectedError, never, BulkheadRejectedError>
Is this one of the errors this pipeline can produce (E)? Resilience errors and mapError results.
isError(
var e:unknown
e))
var console:Console
The console module provides a simple debugging console that is similar to the
JavaScript console mechanism provided by web browsers.
The module exports two specific components:
A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
A global console instance configured to write to process.stdout and
process.stderr. The global console can be used without importing the node:console module.
Warning: The global console object's methods are neither consistently
synchronous like the browser APIs they resemble, nor are they consistently
asynchronous like all other Node.js streams. See the note on process I/O for
more information.
Example using the global console:
console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(newError('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
constname='Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr
Example using the Console class:
constout=getStreamSomehow();
consterr=getStreamSomehow();
constmyConsole=new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(newError('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
Prints to stdout with newline. Multiple arguments can be passed, with the
first used as the primary message and all additional used as substitution
values similar to printf(3)
(the arguments are all passed to util.format()).
match<T, E, HextendsOutcomeHandlers<T, E, unknown>>(outcome:Outcome<T, E>, handlers:H):ReturnType<H[keyofH] & ((...args:any) =>any)>;
}
The result of an execution: either a value or an error. Strategies pass outcomes around instead of throwing.
E is the error type when it's known (see pipeline.settle()), unknown otherwise.
Outcome.
try: <{
port:number;
}, ConfigError>(options: {
try: () => {
port:number;
};
catch: (error:unknown) =>ConfigError;
}) =>Outcome<{
port:number;
}, ConfigError> (+1 overload)
try({
try: () => {
port: number;
}
try: () =>
varJSON:JSON
An intrinsic object that provides functions to convert JavaScript values to and from the JavaScript Object Notation (JSON) format.
JSON.
JSON.parse(text: string, reviver?: (this:any, key:string, value:any) => any): any
Converts a JavaScript Object Notation (JSON) string into an object.
@param ― text A valid JSON string.
@param ― reviver A function that transforms the results. This function is called for each member of the object.
If a member contains nested objects, the nested objects are transformed before the parent object is.
@throws ― {SyntaxError} If text is not valid JSON.
registerResultAdapter teaches settle() and Outcome.from() another library’s Result type (neverthrow,
ts-results, Effect’s Either…). A returned Err then joins the typed channel like Outcome.fromError:
match<T, E, HextendsOutcomeHandlers<T, E, unknown>>(outcome:Outcome<T, E>, handlers:H):ReturnType<H[keyofH] & ((...args:any) =>any)>;
}
The result of an execution: either a value or an error. Strategies pass outcomes around instead of throwing.
E is the error type when it's known (see pipeline.settle()), unknown otherwise.
match<T, E, HextendsOutcomeHandlers<T, E, unknown>>(outcome:Outcome<T, E>, handlers:H):ReturnType<H[keyofH] & ((...args:any) =>any)>;
}
The result of an execution: either a value or an error. Strategies pass outcomes around instead of throwing.
E is the error type when it's known (see pipeline.settle()), unknown otherwise.
The rate limiters are typed as RateLimiterRejectedError, whose code covers RATE_LIMITED, BULKHEAD_FULL,
PERMIT_LIMIT_EXCEEDED and RATE_LIMIT_DENIED. After addRateLimiter(), match asks for all four.
HTTP status mapping and describeResilienceError() are in Error codes.
If two copies of the package are loaded (ESM and CJS, or nested installs), instanceof silently returns false.
The guards check registered symbols instead and work across copies: