This method looks useful to handle errors in one place instead of placing handleError(action: F[T]) in each serverLogic definition. Is there any analog in latest versions?
Also it is still in docs Error handling β tapir 1.x documentation
@Denis_N thank you for pointing out the outdated documentation. I think that current recommended approach is to use .serverLogicRecoverErrors
as described here. Would that be ok for your needs?
Well it seems like it should be used per-endpoint too or describe every possible error in stringBody.map(MyError) . I was looking for a solution where you could just do Throwable => Response
on all routes in the app. I tried to do so on http4s level but it seems Tapir already handles all errors to Response with 500 at itβs level.
If you donβt want the default Exception => error response mechanism provided by .serverLogicRecoverErrors
, but a mechanism allowing to map exceptions to responses with a custom function hooked globally, you can leverage endpoint interceptors, using a custom ExceptionInterceptor.
As Krzysiek writes, I think the functionality you are looking for is in the interceptors. You might be fine by customising the built-in exception interceptor, using XServerOptions.customiseInterceptors.exceptionHandler(...)
or .defaultHandlers
to customise all kinds of error responses, that are generated outside of the server logic.
I wanted to fix the docs, and it occured to me that the method is still there, but in a different form: see Server logic β tapir 1.x documentation (I fixes the docs also )