|
@@ -0,0 +1,40 @@
|
|
|
|
|
+package com.leanwo.gateway.exception;
|
|
|
|
|
+
|
|
|
|
|
+import java.io.Reader;
|
|
|
|
|
+
|
|
|
|
|
+import org.slf4j.Logger;
|
|
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
|
|
+import org.springframework.context.annotation.Bean;
|
|
|
|
|
+import org.springframework.context.annotation.Configuration;
|
|
|
|
|
+
|
|
|
|
|
+import com.netflix.hystrix.exception.HystrixBadRequestException;
|
|
|
|
|
+
|
|
|
|
|
+import feign.Response;
|
|
|
|
|
+import feign.codec.ErrorDecoder;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 不进入熔断,直接抛出异常
|
|
|
|
|
+ * @author YangZhiJie
|
|
|
|
|
+ * @date 2020/08/03
|
|
|
|
|
+ */
|
|
|
|
|
+@Configuration
|
|
|
|
|
+public class KeepErrMsgConfiguration {
|
|
|
|
|
+
|
|
|
|
|
+ @Bean
|
|
|
|
|
+ public ErrorDecoder errorDecoder() {
|
|
|
|
|
+ return new UserErrorDecoder();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 自定义错误
|
|
|
|
|
+ */
|
|
|
|
|
+ public class UserErrorDecoder implements ErrorDecoder {
|
|
|
|
|
+ private Logger logger = LoggerFactory.getLogger(getClass());
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Exception decode(String methodKey, Response response) {
|
|
|
|
|
+ String errorMessage = response.body().toString();
|
|
|
|
|
+ return new HystrixBadRequestException(errorMessage);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|