import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.ResponseEntity;
@FeignClient(name = "xxx", url = "xxx", configuration = {ErrorNewDecoder.class})
public interface SingleVehicleConfigUpdaterClient {
@PostMapping(SINGLE_VEHICLE_REMOTE_CONFIG)
ResponseEntity configCtl(@RequestBody xxx request);
}
上面是调用第三方,然后configuration里面配置需要自己重新定义
import com.alibaba.fastjson.JSON;
import com.beantechs.tsp.backend.common.error.BackendError;
import com.beantechs.tsp.backend.common.exception.BackendException;
import feign.Response;
import feign.Util;
import feign.codec.ErrorDecoder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import java.io.IOException;
import java.util.Map;
/**
*
*/
@Slf4j
public class ErrorNewDecoder implements ErrorDecoder {
@Autowired
private ConfigurationClass configurationClass;
private ErrorDecoder defErrorDecoder = new Default();
@Override
public Exception decode(String methodKey, Response response) {
try {
if (response.status() != 200 && response.status() != 201 && response.status() != 204) {
if (null != response.body()) {
String message = Util.toString(response.body().asReader());
log.error("请求异常:{}", message);
}
}
} catch (IOException ex) {
log.error(ex.getMessage(), ex);
}
return defErrorDecoder.decode(methodKey, response);
}
}
齐活~
版权声明:本文为qq_28751497原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。