Skip to content

Commit

Permalink
feature: 全局Controller异常处理器, 目前无法输出 request body,还没有找到实现的方法
Browse files Browse the repository at this point in the history
  • Loading branch information
myoss committed Jun 24, 2019
1 parent f250581 commit 69b7235
Showing 1 changed file with 3 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,17 @@ public Map<String, Object> getErrorAttributes(ServerRequest request, boolean inc
Throwable error = getError(request);
HttpStatus errorStatus = determineHttpStatus(error);
URI requestUrl = request.uri();
String requestBody = null;
HttpMethod method = request.method();
String contentType = request.headers().contentType().map(MimeType::getType).orElse(null);
if (error instanceof RestClientResponseException) {
RestClientResponseException exception = (RestClientResponseException) error;
// 打印出发送http请求的错误信息,帮助追踪错误源
String responseBody = exception.getResponseBodyAsString();
log.error(
"requestUrl: {}, requestMethod: {}, requestBody: {}, contentType: {}\norg.springframework.web.client.RestClientResponseException: {}, responseBody: {} ",
requestUrl, method, requestBody, contentType, exception.getMessage(), responseBody, error);
"requestUrl: {}, requestMethod: {}, contentType: {}\norg.springframework.web.client.RestClientResponseException: {}, responseBody: {} ",
requestUrl, method, contentType, exception.getMessage(), responseBody, error);
} else {
log.error("requestUrl: {}, requestMethod: {}, requestBody: {}, contentType: {}", requestUrl, method,
requestBody, contentType, error);
log.error("requestUrl: {}, requestMethod: {}, contentType: {}", requestUrl, method, contentType, error);
}

String traceId = ApplicationEventTracer.getTraceId();
Expand Down

0 comments on commit 69b7235

Please sign in to comment.