package com.ycl.feign; import com.ycl.exception.FeignException; import feign.Response; import feign.codec.ErrorDecoder; import lombok.extern.slf4j.Slf4j; import org.springframework.context.annotation.Configuration; /** * feign的错误解码器 * * @author:xp * @date:2024/7/14 11:30 */ @Slf4j @Configuration public class FeignErrorDecoder implements ErrorDecoder { @Override public Exception decode(String methodKey, Response response) { String msg = ""; switch (response.status()) { case 400: msg = "远程调用异常:参数错误"; break; case 401: msg = "远程调用异常:未登录,无法操作"; break; case 403: msg = "远程调用异常:无权限执行操作"; break; case 404: msg = "远程调用异常:调用接口不存在"; break; case 500: msg = "远程调用异常:对方服务500异常"; break; default: msg = "远程调用异常:未知异常"; break; } log.error(msg); return new FeignException(msg); } }