Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Idiomatic way of implementing global error handler in http4k

Tags:

kotlin

http4k

I tried to find an answer in project's documentation but couldn't find anything useful.

What is the best practice to implement a global error handler that captures all the exceptions and returns appropriate http status based on the exception type?

like image 714
alisabzevari Avatar asked Sep 18 '25 17:09

alisabzevari


1 Answers

For this you should implement an http4k Filter.

The API docs have a list of all the current filters that are implemented: https://www.http4k.org/api/org.http4k.filter/

Specifically for this, you want to add a ServerFilters.CatchAll into your filter chain. If you click through you can see the implementation:

https://www.http4k.org/api/org.http4k.filter/-server-filters/-catch-all/

like image 89
David D Avatar answered Sep 21 '25 12:09

David D