fix(feign): 修复FR返回类型未反序列化,丢失错误消息的问题
This commit is contained in:
+6
-3
@@ -25,6 +25,7 @@
|
||||
*/
|
||||
package org.springblade.core.cloud.feign;
|
||||
|
||||
import com.fasterxml.jackson.databind.JavaType;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import feign.FeignException;
|
||||
import lombok.AllArgsConstructor;
|
||||
@@ -85,8 +86,8 @@ public class BladeFeignFallback<T> implements MethodInterceptor {
|
||||
return JSON.parseObject(body, returnType);
|
||||
}
|
||||
}
|
||||
// 暂时不支持 flux,rx,异步等,返回值不是 R,直接返回 null。
|
||||
if (R.class != returnType) {
|
||||
// 暂时不支持 flux,rx,异步等,返回值不是 R(或其子类,如 FR),直接返回 null。
|
||||
if (!R.class.isAssignableFrom(returnType)) {
|
||||
return null;
|
||||
}
|
||||
// 非 FeignException
|
||||
@@ -103,7 +104,9 @@ public class BladeFeignFallback<T> implements MethodInterceptor {
|
||||
JsonNode resultNode = JsonUtil.readTree(content);
|
||||
// 判断是否 R 格式 返回体
|
||||
if (resultNode.has(CODE)) {
|
||||
return JsonUtil.getInstance().convertValue(resultNode, R.class);
|
||||
// 支持 R 及其子类(如 FR)的泛型反序列化,保留服务端失败原因
|
||||
JavaType javaType = JsonUtil.getInstance().getTypeFactory().constructType(method.getGenericReturnType());
|
||||
return JsonUtil.getInstance().convertValue(resultNode, javaType);
|
||||
}
|
||||
return R.fail(resultNode.toString());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user