我正在開發一個使用 Dropwizard 的應用程序,它有這個 ExceptionMapper 的實現:https : //github.com/dropwizard/dropwizard/blob/master/dropwizard-jersey/src/main/java/io/dropwizard/jersey/errors /LoggingExceptionMapper.java這個實現的問題在于,即使它同時捕獲了 4** 和 5** 錯誤,它也只記錄了 5** 錯誤。我需要實現 ExceptionMapper 以便根本不使用 LoggingExceptionMapper 并且我的 CustomExceptionMapper 記錄 CLIENT_ERRORs 和 SERVER_ERRORs。我想知道我的應用程序如何知道它需要使用 CustomExceptionMapper 而不是 Dropwizard 類?將 CLIENT_ERROR 添加到 if 條件是否足以注銷所有錯誤?@Overridepublic Response toResponse(E exception) { // If we're dealing with a web exception, we can service certain types of request (like // redirection or server errors) better and also propagate properties of the inner response. if (exception instanceof WebApplicationException) { final Response response = ((WebApplicationException) exception).getResponse(); Response.Status.Family family = response.getStatusInfo().getFamily(); if (family.equals(Response.Status.Family.REDIRECTION)) { return response; } if (family.equals(Response.Status.Family.SERVER_ERROR) || family.equals(Response.Status.Family.CLIENT_ERROR) { logException(exception); } return Response.fromResponse(response) .type(MediaType.APPLICATION_JSON_TYPE) .entity(new ErrorMessage(response.getStatus(), exception.getLocalizedMessage())) .build(); }或者有沒有更好的方法來做到這一點?
添加回答
舉報
0/150
提交
取消