Handling Effect Results and Errors in TypeScript

Idiomatic style question. I have the an effect which either returns a value, or one of several errors. I need to transform these into three cases:
- for the value, I need to do an operation on it and return it
- for some of the errors, I need to do a different operation and return it
- for the remainder of the errors, I should propagate the failure unchanged.

I'm not entirely sure what the best way to do this is. If I use Effect.catchTags, I lose information about whether the value I get back is from an Effect success or a caught error success. If I use Effect.either, I lose the extremely nice api where any errors I don't catch in catchTags are propagated. Any suggestions?

So far I have:
const result = yield* Effect.either(myEffect);
if (Either.isRight(result)) { return ... }
const error = result.left;
const handledError = Match.value(error).pipe(
  Match.tag(.....)
  ......,
  Match.either
)
if (Either.isRight(handledError) { return handledError.right; }
yield* Effect.fail(handledError.left);


This seems pretty complicated, is there something simpler I'm missing?
Was this page helpful?