use of core.framework.impl.web.service.ErrorResponse in project core-ng-project by neowu.
the class HTTPServerErrorHandler method handleError.
void handleError(Throwable e, HttpServerExchange exchange, RequestImpl request, ActionLog actionLog) {
if (exchange.isResponseStarted()) {
logger.error("response was sent, discard the current http transaction");
return;
}
try {
Response errorResponse = null;
if (customErrorHandler != null) {
Optional<Response> customErrorResponse = customErrorHandler.handle(request, e);
if (customErrorResponse.isPresent())
errorResponse = customErrorResponse.get();
}
if (errorResponse == null) {
String accept = exchange.getRequestHeaders().getFirst(Headers.ACCEPT);
errorResponse = defaultErrorResponse(e, accept, actionLog);
}
responseHandler.render((ResponseImpl) errorResponse, exchange, actionLog);
} catch (Throwable error) {
logger.error(error.getMessage(), e);
if (exchange.isResponseStarted()) {
logger.error("failed to render error page, response was sent, discard the current http transaction");
return;
}
renderDefaultErrorPage(error, exchange, actionLog);
}
}
use of core.framework.impl.web.service.ErrorResponse in project core-ng-project by neowu.
the class HTTPServerErrorHandlerTest method errorResponse.
@Test
void errorResponse() {
ErrorResponse response = handler.errorResponse(new Error("test-message"), null);
assertEquals("test-message", response.message);
assertEquals("INTERNAL_ERROR", response.errorCode);
assertEquals("ERROR", response.severity);
}
use of core.framework.impl.web.service.ErrorResponse in project core-ng-project by neowu.
the class HTTPServerErrorHandlerTest method errorResponseWithErrorCodeException.
@Test
void errorResponseWithErrorCodeException() {
ErrorResponse response = handler.errorResponse(new NotFoundException("test-message", "TEST_ERROR_CODE"), null);
assertEquals("test-message", response.message);
assertEquals("TEST_ERROR_CODE", response.errorCode);
assertEquals("WARN", response.severity);
}
use of core.framework.impl.web.service.ErrorResponse in project core-ng-project by neowu.
the class HTTPServerErrorHandler method errorResponse.
ErrorResponse errorResponse(Throwable e, String actionId) {
ErrorResponse 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;
}
Aggregations