Support for Jersey MappableException in 'DefaultJerseyTagsProvider'
See original GitHub issueI am using Micrometer in my Jersey application and i have noticed that the DefaultJerseyTagsProvider
can’t handle MappableException
.
Here is an extract from the DefaultJerseyTagsProvider
code:
private static int statusCode(RequestEvent event) {
Throwable exception = event.getException();
if (exception != null) {
if (exception instanceof WebApplicationException) {
return ((WebApplicationException) exception).getResponse().getStatus();
}
return Response.Status.INTERNAL_SERVER_ERROR.getStatusCode();
}
return event.getContainerResponse().getStatus();
}
With that code, whenever we have an exception that is not a WebApplicationException
, we will have a 500 status code…
When using MappableException
, application exceptions are mapped to Jersey Response (with an appropriate response status).
For example, the ValidationExceptionMapper
from Jersey should return a 400 (Bad Request) when request parameters validation fails.
As a consequence, when using micrometer-jersey2, i am expecting a http.server.requests
metric with a {status = 400} tag when my request is not valid but i only have {status = 500} tags.
Should it be possible to add support for MappableException
so as the status tag value would be the same than the response status code?
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (6 by maintainers)
PR is merged. Thanks again!
Yeah, also looked a bit and came to the same conclusion. So within the
statusCode()
we don’t even have to handle any exceptions, just figure if theContainerResponse
is there and use itsgetStatus()
, otherwise returnResponse.Status.INTERNAL_SERVER_ERROR.getStatusCode()
.Thanks for looking into it!
PS: PR against branch
1.0.x
please.