How to Implement Top-Level Error Handling in HttpApiBuilder
I'm working with the HttpApiBuilder API to build out my API specification, setup handlers, and serve the API. I'm interested in setting up top level error handling (ex: defect occurs in route handler, we convert to standard format fallback error, route not found error, etc.). One way that I was able to get this working was by piping the result of every handler setup in
I found this section of the docs that talks about something similar but it works with the HttpRouter API: https://github.com/Effect-TS/effect/tree/main/packages/platform#catching-errors
I wasn't sure how to do something similar within the context of the HttpApiBuilder which manages a router internally. I played around with middleware a bit but concluded that by the time you do something like
So the question is: Is there some way where I can just define this fallback logic once at the top level rather than for each individual handler?
HttpApiBuilder.group to Effect.catchAllCause which then handled the defect. However, I'd ideally like to accomplish this at the top level of my api (so I don't run the risk of forgetting to do this with new handlers as the API grows in size. I found this section of the docs that talks about something similar but it works with the HttpRouter API: https://github.com/Effect-TS/effect/tree/main/packages/platform#catching-errors
I wasn't sure how to do something similar within the context of the HttpApiBuilder which manages a router internally. I played around with middleware a bit but concluded that by the time you do something like
app.pipe(Effect.catchAllCause(... within a middleware effect, it's too late to modify the response as it was already sent back to the client. So the question is: Is there some way where I can just define this fallback logic once at the top level rather than for each individual handler?
