use of core.framework.api.http.HTTPStatus in project core-ng-project by neowu.
the class ResponseHandler method render.
public void render(ResponseImpl response, HttpServerExchange exchange, ActionLog actionLog) {
HTTPStatus status = response.status();
exchange.setStatusCode(status.code);
putHeaders(response, exchange);
putCookies(response, exchange);
response.body.send(exchange.getResponseSender(), context);
// set response code context at last, to avoid error handler to log duplicate action_log_context key on exception
actionLog.context("responseCode", status.code);
}
use of core.framework.api.http.HTTPStatus in project core-ng-project by neowu.
the class WebServiceClient method validateResponse.
void validateResponse(HTTPResponse response) {
HTTPStatus status = response.status();
if (status.code >= 200 && status.code < 300)
return;
byte[] responseBody = response.body();
try {
ErrorResponse error = JSONMapper.fromJSON(ErrorResponse.class, responseBody);
logger.debug("failed to call remote service, id={}, severity={}, errorCode={}, remoteStackTrace={}", error.id, error.severity, error.errorCode, error.stackTrace);
throw new RemoteServiceException(error.message, parseSeverity(error.severity), error.errorCode);
} catch (RemoteServiceException e) {
throw e;
} catch (Throwable e) {
String responseText = response.text();
logger.warn("failed to decode response, statusCode={}, responseText={}", status.code, responseText, e);
throw new RemoteServiceException(Strings.format("internal communication failed, status={}, responseText={}", status.code, responseText), Severity.ERROR, "REMOTE_SERVICE_ERROR", e);
}
}
Aggregations