<@U0BN9C0HM> for that you should use a Filter and ...
# http4k
d
@krtko for that you should use a Filter and just wrap your handler (or entire app) using
then()
. We provide the one below which should give you a general idea, but you can easily write your own to plug in whatever logger you need:
Copy code
object CatchAll {
        operator fun invoke(errorStatus: Status = INTERNAL_SERVER_ERROR): Filter = Filter { next ->
            {
                try {
                    next(it)
                } catch (e: Exception) {
                    val sw = StringWriter()
                    e.printStackTrace(PrintWriter(sw))
                    Response(errorStatus).body(sw.toString())
                }
            }
        }
    }
k
Thanks so if I wanted to add some general headers onto all of my responses, using a filter would be the route to go?
d
yep
k
Thank you