# Is there any toRouteRecoverErrors method analog in latest versions?

**URL:** <https://softwaremill.community/t/is-there-any-torouterecovererrors-method-analog-in-latest-versions/222>\
**Category:** tapir\
**Created:** [June 7, 2023, 8:04am UTC](https://softwaremill.community/t/is-there-any-torouterecovererrors-method-analog-in-latest-versions/222 "2023-06-07T08:04:22Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Denis\_N](https://avatars.discourse-cdn.com/v4/letter/d/8491ac/32.png) [@Denis\_N](https://softwaremill.community/u/Denis_N)\
**Post date:** [June 7, 2023, 8:04am UTC](https://softwaremill.community/t/is-there-any-torouterecovererrors-method-analog-in-latest-versions/222/1 "2023-06-07T08:04:22Z")

</div>

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](https://tapir.softwaremill.com/en/latest/server/errors.html#error-outputs)

---

<div class="post-metadata">

**Author:** ![kciesielski](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/kciesielski/32/133_2.png) [@kciesielski](https://softwaremill.community/u/kciesielski)\
**Post date:** [June 7, 2023, 11:11am UTC](https://softwaremill.community/t/is-there-any-torouterecovererrors-method-analog-in-latest-versions/222/2 "2023-06-07T11:11:15Z")

</div>

@Denis_N thank you for pointing out the outdated documentation. I think that current recommended approach is to use `.serverLogicRecoverErrors` as described [here](https://tapir.softwaremill.com/en/latest/server/logic.html?highlight=serverLogicRecoverErrors#recovering-errors-from-failed-effects). Would that be ok for your needs?

---

<div class="post-metadata">

**Author:** ![Denis\_N](https://avatars.discourse-cdn.com/v4/letter/d/8491ac/32.png) [@Denis\_N](https://softwaremill.community/u/Denis_N)\
**Post date:** [June 7, 2023, 11:58am UTC](https://softwaremill.community/t/is-there-any-torouterecovererrors-method-analog-in-latest-versions/222/3 "2023-06-07T11:58:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![kciesielski](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/kciesielski/32/133_2.png) [@kciesielski](https://softwaremill.community/u/kciesielski)\
**Post date:** [June 7, 2023, 12:50pm UTC](https://softwaremill.community/t/is-there-any-torouterecovererrors-method-analog-in-latest-versions/222/4 "2023-06-07T12:50:37Z")

</div>

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](https://tapir.softwaremill.com/en/latest/server/interceptors.html?highlight=interceptors#endpoint-interceptors), using a custom ExceptionInterceptor.

---

<div class="post-metadata">

**Author:** ![adamw](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/adamw/32/28_2.png) [@adamw](https://softwaremill.community/u/adamw)\
**Post date:** [June 7, 2023, 7:33pm UTC](https://softwaremill.community/t/is-there-any-torouterecovererrors-method-analog-in-latest-versions/222/5 "2023-06-07T19:33:07Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![adamw](https://dub1.discourse-cdn.com/flex005/user_avatar/softwaremill.community/adamw/32/28_2.png) [@adamw](https://softwaremill.community/u/adamw)\
**Post date:** [June 12, 2023, 1:17pm UTC](https://softwaremill.community/t/is-there-any-torouterecovererrors-method-analog-in-latest-versions/222/6 "2023-06-12T13:17:21Z")

</div>

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](https://tapir.softwaremill.com/en/latest/server/logic.html#recovering-errors-from-failed-effects) (I fixes the docs also 😉 )
