Effect CommunityEC
Effect Community3y ago
9 replies
Raskyer

Understanding `catchTag` for Error Handling

Hello,
I have a weird understanding of catchTag I guess.
Here is my code :
class RedirectError {
  _tag = 'Redirect';
  constructor(public url: string) {}
}
class BadRequestError {
  _tag = 'BadRequest';
  constructor(public message: string) {}
}
type ResponseError = RedirectError | BadRequestError;

type Fn = () => Effect.Effect<never, ResponseError, number>;

function test(fn: Fn) {
  const effect = fn();
  effect.pipe(
    Effect.catchTag("Redirect", err => Effect.succeeed(-1)),
    Effect.catchTag("BadRequest", err => Effect.succeed(-2))
  );
}


But this produces the following error in screenshot.
Is it a bug or am I missing something ?
image.png
Was this page helpful?