Effect CommunityEC
Effect Community8mo ago
5 replies
Moshizzl3

How do i catch `HttpApiDecodeError` in `@effect/platform`

I am using the
HttpApi
module in
@effect/platform
to build my API. I am having some trouble understand where the decode error happens and how to catch it.
I followed the code references and i see that the handler transforms the parseError into the HttpApiDecodeError.

1. I want to be able to catch this error, and do some logging (nothing is logged at the moment).
2. if possible i would also like to map it my own error, as i need to return a specific format to the client.

I have tried to add it to the catchTags effect where i handle other errors (when creating the Live group for my API):

export const SomeGroupLive = HttpApiBuilder.group(api, "some", (handlers) => {
  return handlers.handle("someThing", (input) =>
    runSomeEffect(input.payload)
      .pipe(
        Effect.catchTags({
          ErrorOne: (e) =>
            APIErrors.APIInternalError.create({
              message: e.message,
            }),
          ErrorTwo: (e) =>
            APIErrors.APIInternalError.create({
              message: e.message,
            }),
            ...
          HttpApiDecodeError: (e) =>
            APIErrors.APIInternalError.create({
              message: e.message,
            }),
        }),
      ),
  );
});

This does nothing, which means the error is probably handled somewhere else? How could i then catch it?
Was this page helpful?