Encapsulating Reusable Error Handling Logic in Effect Functions

Hi guys! I would like an opinion on what would be the idiomatic way to do re-usable functions in effect to do re-usable error handling functions. Apologies if this seems like a very trivial question, just want to make sure i'm not missing any of Effect's features where i could use to make my life easier.

i have a function like this where I want to catchTag then map it to a new class like this. I need the catchTag logic in many places, how would I go about encapsulating this logic? Would it be something as simple as the 2nd code snippet I have shown here?

would appreciate any advice!

const result = await updatePhoneNumberDestinationHandler(ctx, args).pipe(
      Effect.catchTag("DuplicatedPhoneNumber", (e) => {
        const test = S.encodeUnknownSync(DuplicatedPhoneNumber)(e);
        return Effect.succeed(new ConvexError(test));
      }),
      Effect.runPromise,
    );


const handleError = Effect.catchTag("DuplicatedPhoneNumber", (e) => {
        const test = S.encodeUnknownSync(DuplicatedPhoneNumber)(e);
        return Effect.succeed(new ConvexError(test));
 })

const result = await updatePhoneNumberDestinationHandler(ctx, args).pipe(
      handleError,
      Effect.runPromise,
    );
Was this page helpful?