Handling Errors and Piping in Effect Typescript

export const AuthLive = HttpApiBuilder.group(PublicApi, "auth", (handlers) =>
  Effect.gen(function* () {
    const { Login, Logout, createUser } = yield* AuthRepository;
    return handlers
      .handle(
        "Login",
        Effect.fn(function* ({ payload }) {
          const token = yield* Login(payload.username, payload.password).pipe(
            Effect.catchTag("SqlError", Effect.die)
          );
          // we need to set the cookie!!
          yield* HttpApiBuilder.securitySetCookie(ApiKey, token);
        })
      )
      .handle(
        "Register",
        Effect.fn(function* ({ payload }) {
          const user = yield* createUser(
            payload.username,
            Redacted.value(payload.password)
          ).pipe(Effect.catchTag("SqlError", Effect.die));
          const token = yield* Login(payload.username, payload.password).pipe(
            Effect.catchTag("SqlError", Effect.die)
          );
          // we need to set the cookie!!

          yield* HttpApiBuilder.securitySetCookie(ApiKey, token);
        })
      )
      .handle("Logout", () =>
        Logout.pipe(Effect.catchTag("SqlError", Effect.die))
      )
      .handle("User", () => CurrentUser);
  })
);


1. with my authrepo service, how do i make it so i dont have to manually catch the SqlError in every single one when using it to define the api?
is this maybe just the wrong idea coming from js, and i should just have to handle all my errors?
2. how do you pipe from
Effect.fn
, or is it not possible? i cant use catchTag on
Effect.fn
so i need to duplicate those :/
Was this page helpful?