Handling Specific Errors with `catchTag` and `catchAll` in TypeScript

Is there a way to catch a specific error by tag and handle all others with catchAll? Something like:

.pipe(
  Effect.catchTag(
    "NoSuchElementException",
    () =>
      new ProductNotFoundError({
        message: `Product ${dto.id} was not found.`,
      }),
  ),
  Effect.catchAll(
    (cause) =>
      new GenericError({
        cause,
      }),
  )
)
Was this page helpful?