Vojtěch Knyttl
12/06/2020, 7:22 AMFilter
implemented in the example I am only getting 400 BAD REQUEST
whereas Jackson provides a nice error description. Is it possible to get this very description to log within the logging filter?
https://gist.github.com/knyttl/bd0ffe5474e14a9e64f71d78249bac5bdave
12/06/2020, 8:02 AMVojtěch Knyttl
12/06/2020, 9:11 AMval jsonResultLens = Body.json().toLens().asResult()
val jsonResult: Result<JsonNode, LensFailure> = jsonResultLens(Request(GET, "/foo"))
println(jsonResult)
is this what you meant? using jsonResultLens
within the filter? however the method .asResult()
seems to be missing - hasn't it been removed?dave
12/06/2020, 9:26 AMdave
12/06/2020, 9:27 AMVojtěch Knyttl
12/06/2020, 9:35 AMVojtěch Knyttl
12/06/2020, 9:41 AMVojtěch Knyttl
12/06/2020, 9:41 AMVojtěch Knyttl
12/06/2020, 9:41 AMVojtěch Knyttl
12/06/2020, 9:43 AMval loggingFilter = Filter { next: HttpHandler ->
{ request: Request ->
val response = next(request)
<http://log.info|log.info>(response.status.description)
// 400 BAD_REQUEST, no error details
response
}
}
you can see here, that this is just response.status, no LensFailure exceptionVojtěch Knyttl
12/06/2020, 9:45 AMdave
12/06/2020, 9:57 AMdave
12/06/2020, 9:57 AMVojtěch Knyttl
12/06/2020, 10:42 AMVojtěch Knyttl
12/06/2020, 10:48 AMPreFlightExtraction.Companion.None
, but still no exception within the logging filter)dave
12/06/2020, 10:50 AMVojtěch Knyttl
12/06/2020, 11:19 AMtrapping the erorr
you mean the exception catching here:
try {
next(it)
} catch( e: LensFailure){
Response(BAD_REQUEST).body(e.cause?.localizedMessage ?: "")
}
?Vojtěch Knyttl
12/06/2020, 11:19 AMdave
12/06/2020, 11:22 AMHTTP/1.1 400 Bad Request
Unexpected end-of-input: was expecting closing quote for a string value
at [Source: (String)"{"name":"}"; line: 1, column: 11] (through reference chain: Blob["name"])
Vojtěch Knyttl
12/06/2020, 11:22 AMfun CatchLensFailure(failResponseFn: (LensFailure) -> Response = {
Response(BAD_REQUEST.description(it.failures.joinToString("; ")))
}) = Filter { next ->
{
try {
next(it)
} catch (lensFailure: LensFailure) {
when {
lensFailure.target is Response -> throw lensFailure
lensFailure.target is RequestContext -> throw lensFailure
lensFailure.overall() == Failure.Type.Unsupported -> Response(UNSUPPORTED_MEDIA_TYPE)
else -> failResponseFn(lensFailure)
}
}
}
}
It seems it ends here in the else
branch - it catches the exception and retruns responseVojtěch Knyttl
12/06/2020, 11:25 AMloggingFilter.then(handler)(request)
dave
12/06/2020, 11:26 AMdave
12/06/2020, 11:26 AMVojtěch Knyttl
12/06/2020, 11:28 AMdave
12/06/2020, 11:28 AMVojtěch Knyttl
12/06/2020, 11:28 AMdave
12/06/2020, 11:29 AMVojtěch Knyttl
12/06/2020, 7:21 PMdave
12/07/2020, 4:00 AMdave
12/07/2020, 4:01 AMdave
12/07/2020, 4:04 AMVojtěch Knyttl
12/07/2020, 9:08 AMVojtěch Knyttl
12/07/2020, 9:08 AM