Validating Errors in tryPromise with Custom Handling in TypeScript
Is this the correct way to validate an error from tryPromise ? it looks like lot of LOC but maybe it is necessary:
const resp = yield* Effect.tryPromise({
try: () => pubsub.topic(topic).subscription(name).get(),
catch: (e) => {
const decode = S.decodeUnknownOption(GetSubscriptionErrorSchema);
const maybeDecoded = decode(e);
return Match.value(maybeDecoded).pipe(
Match.when(
{ value: { code: 5 } },
() => new SubscriptionNotFound({ subscriptionName: name }),
),
Match.orElse(() => new UnknownException(e)),
);
},
});