HTTPErrorHandler { Object errorResponse(Throwable e, String userAgent, String actionId) { if (WebServiceClient.USER_AGENT.equals(userAgent)) { var response = new ErrorResponse(); response.id = actionId; response.message = e.getMessage(); response.stackTrace = Exceptions.stackTrace(e); if (e instanceof ErrorCode) { ErrorCode errorCode = (ErrorCode) e; response.errorCode = errorCode.errorCode(); response.severity = errorCode.severity().name(); } else { response.errorCode = "INTERNAL_ERROR"; response.severity = Severity.ERROR.name(); } return response; } else { var response = new AJAXErrorResponse(); response.id = actionId; response.message = e.getMessage(); if (e instanceof ErrorCode) { response.errorCode = ((ErrorCode) e).errorCode(); } else { response.errorCode = "INTERNAL_ERROR"; } return response; } } HTTPErrorHandler(ResponseHandler responseHandler);  public ErrorHandler customErrorHandler; }
@Test void errorResponseWithErrorCodeException() { var expected = new ErrorResponse(); expected.id = "actionId"; expected.message = "test message"; expected.errorCode = "TEST_ERROR_CODE"; expected.severity = "WARN"; var response = handler.errorResponse(new NotFoundException("test message", "TEST_ERROR_CODE"), WebServiceClient.USER_AGENT, "actionId"); assertThat(response).isInstanceOf(ErrorResponse.class) .usingRecursiveComparison().ignoringFields("stackTrace") .isEqualTo(expected); }
@Test void errorResponse() { var expected = new ErrorResponse(); expected.id = "actionId"; expected.message = "test message"; expected.errorCode = "INTERNAL_ERROR"; expected.severity = "ERROR"; var response = handler.errorResponse(new Error("test message"), WebServiceClient.USER_AGENT, "actionId"); assertThat(response).isInstanceOf(ErrorResponse.class) .usingRecursiveComparison().ignoringFields("stackTrace") .isEqualTo(expected); }
@Test void ajaxErrorResponse() { var expected = new AJAXErrorResponse(); expected.id = "actionId"; expected.message = "test message"; expected.errorCode = "INTERNAL_ERROR"; var response = handler.errorResponse(new Error("test message"), "Mozilla/5.0", "actionId"); assertThat(response).isInstanceOf(AJAXErrorResponse.class) .usingRecursiveComparison().ignoringFields("stackTrace") .isEqualTo(expected); }