Sorry... but I met another problem... I want to b...
# http4k
r
Sorry... but I met another problem... I want to build a Filter which can catch
ApiException
thrown in handler, and then wraps then into a
val error = Body.auto<ApiException>().toLens()
, so i can avoid use
return@run Response(...).with(...)
in every place rejecting a malformed request with a json body which constituted of reason and custom diagnose info. so i write this, as learn from `CatchLensFailure`:
Copy code
private val filterChain by lazy {
    Filter.NoOp.then(Filter { next ->
        {
            try {
                next(it)
            } catch (e: ApiException) {
                Response(Status.BAD_REQUEST).with(error of e)
            }
        }
    })
}
but seems that whenever the
of
operator meets something
Exception
, it not works. instead of construct the content, it'll print the stacktrace. i debug and examine the stacktrace but still cant find where is this behavior defined... is there any workaround...?