Troubleshooting a Hanging Execution with `Match`er

Creating an effect using a Matcher, the execution hangs and don't know how to understand/debug where the problem lies.

// (input: number) => Effect.Effect<never, RecoverableError, void>
const matchResponseStatus = Match.type<
  globalThis.Response["status"]
>().pipe(
  Match.when(constants.HTTP_STATUS_OK, () => Effect.unit),
  Match.when(constants.HTTP_STATUS_PAYLOAD_TOO_LARGE, () => Effect.die(new RequestFailed())),
  Match.when(420, () => Effect.die(new RequestFailed())),
  Match.when(constants.HTTP_STATUS_UNPROCESSABLE_ENTITY, () => Effect.die(new RequestFailed())),
  Match.when(constants.HTTP_STATUS_TOO_MANY_REQUESTS, () => Effect.fail(new RecoverableError()),
  Match.when(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR, () => Effect.fail(new RecoverableError()),
  Match.when(constants.HTTP_STATUS_SERVICE_UNAVAILABLE,() => Effect.fail(new RecoverableError()),
  Match.orElse(() => Effect.die(new RequestFailed())),
);

// snip 

pipe(
  Effect.tryPromise({
    try: (signal) => globalThis.fetch(new globalThis.Request({ /* snip */ }), { signal }),
    catch: () => new RecoverableError(),
  }),
  Effect.tap(Console.log), // This logs
  Effect.flatMap((response) => matchResponseStatus(response.status)),
  Effect.tap(Console.log), // This doesn't
)


PS: the code is simplified. Most of the errors has arguments passed to them
Was this page helpful?