You've already forked FrameTour-BE
refactor: 移除 FeignConfig 类
删除了 FeignConfig 类及相关配置,包括日志级别设置、请求拦截器、错误解码器等。这部分配置可能已经不再需要,或者已经被其他配置所替代。
This commit is contained in:
@@ -1,63 +0,0 @@
|
|||||||
package com.ycwl.basic.config;
|
|
||||||
|
|
||||||
import feign.Logger;
|
|
||||||
import feign.RequestInterceptor;
|
|
||||||
import feign.codec.ErrorDecoder;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.web.context.request.RequestContextHolder;
|
|
||||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
|
||||||
|
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
@Configuration
|
|
||||||
public class FeignConfig {
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public Logger.Level feignLoggerLevel() {
|
|
||||||
return Logger.Level.BASIC;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public RequestInterceptor requestInterceptor() {
|
|
||||||
return requestTemplate -> {
|
|
||||||
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
|
||||||
if (attributes != null) {
|
|
||||||
HttpServletRequest request = attributes.getRequest();
|
|
||||||
|
|
||||||
// 传递认证头
|
|
||||||
String authorization = request.getHeader("Authorization");
|
|
||||||
if (authorization != null) {
|
|
||||||
requestTemplate.header("Authorization", authorization);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public ErrorDecoder errorDecoder() {
|
|
||||||
return new FeignErrorDecoder();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class FeignErrorDecoder implements ErrorDecoder {
|
|
||||||
private final ErrorDecoder defaultErrorDecoder = new Default();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Exception decode(String methodKey, feign.Response response) {
|
|
||||||
log.error("Feign调用失败: method={}, status={}, reason={}",
|
|
||||||
methodKey, response.status(), response.reason());
|
|
||||||
|
|
||||||
if (response.status() >= 400 && response.status() < 500) {
|
|
||||||
// 4xx错误,客户端错误
|
|
||||||
return new RuntimeException("客户端请求错误: " + response.reason());
|
|
||||||
} else if (response.status() >= 500) {
|
|
||||||
// 5xx错误,服务器错误
|
|
||||||
return new RuntimeException("服务器内部错误: " + response.reason());
|
|
||||||
}
|
|
||||||
|
|
||||||
return defaultErrorDecoder.decode(methodKey, response);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user