Skip to content

v2.4.0

Choose a tag to compare

@dmmulroy dmmulroy released this 20 Jan 13:14
dc86a30

What's Changed

Features

Conditional Retry with shouldRetry predicate

Result.tryPromise now accepts a shouldRetry predicate in retry config to control which errors trigger retries:

await Result.tryPromise({
  try: () => fetch(url),
  catch: e => e instanceof TypeError ? new RetryableError(e) : new FatalError(e)
}, {
  retry: {
    times: 3,
    delayMs: 100,
    backoff: "exponential",
    shouldRetry: e => e._tag === "RetryableError"
  }
})

Async catch handler support

The catch handler in Result.tryPromise now supports async functions, enabling error enrichment patterns:

await Result.tryPromise({
  try: () => callApi(url),
  catch: async (e) => {
    const limited = await redis.get(`ratelimit:${userId}`);
    return new ApiError({ cause: e, rateLimited: !!limited });
  }
}, {
  retry: { times: 3, delayMs: 100, backoff: "exponential", shouldRetry: e => !e.rateLimited }
})

Other

  • Improved documentation with additional examples for Result.gen and Result.tryPromise

Full Changelog: v2.3.1...v2.4.0