mirror of
https://github.com/Sagit-chu/flvx.git
synced 2026-09-30 00:06:38 +08:00
兼容v6
This commit is contained in:
-3
@@ -34,9 +34,6 @@ public class GlobalExceptionHandler {
|
||||
|
||||
@ExceptionHandler(value = Exception.class)
|
||||
public R Exception(Exception e){
|
||||
if (e instanceof ClientAbortException) {
|
||||
return null; // 不需要返回值
|
||||
}
|
||||
log.error("异常:----------------{}", e.getMessage());
|
||||
return R.err(-2, "异常错误");
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.springframework.http.client.ClientHttpResponse;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.client.ResponseErrorHandler;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.util.StreamUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
@@ -100,16 +101,34 @@ public class HttpUtils implements ApplicationContextAware {
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义错误处理器,不抛出异常
|
||||
* 自定义错误处理器,不抛出异常但记录错误信息
|
||||
*/
|
||||
private static class NoOpResponseErrorHandler implements ResponseErrorHandler {
|
||||
@Override
|
||||
public boolean hasError(ClientHttpResponse response) throws IOException {
|
||||
return false;
|
||||
HttpStatus statusCode = response.getStatusCode();
|
||||
return statusCode.series() == HttpStatus.Series.CLIENT_ERROR ||
|
||||
statusCode.series() == HttpStatus.Series.SERVER_ERROR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleError(ClientHttpResponse response) throws IOException {
|
||||
HttpStatus statusCode = response.getStatusCode();
|
||||
String statusText = response.getStatusText();
|
||||
String responseBody = "";
|
||||
|
||||
try {
|
||||
// 使用Spring的StreamUtils来读取响应体
|
||||
responseBody = new String(
|
||||
StreamUtils.copyToByteArray(response.getBody()),
|
||||
StandardCharsets.UTF_8
|
||||
);
|
||||
} catch (Exception e) {
|
||||
responseBody = "无法读取响应体: " + e.getMessage();
|
||||
}
|
||||
|
||||
logger.error("HTTP请求错误 - 状态码: {} {}, 响应体: {}",
|
||||
statusCode.value(), statusText, responseBody);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user