|
4 | 4 | import com.alibaba.fastjson.JSONObject; |
5 | 5 | import com.github.dadiyang.httpinvoker.annotation.ExpectedCode; |
6 | 6 | import com.github.dadiyang.httpinvoker.annotation.HttpReq; |
| 7 | +import com.github.dadiyang.httpinvoker.exception.UnexpectedResultException; |
7 | 8 | import com.github.dadiyang.httpinvoker.util.ObjectUtils; |
8 | 9 | import com.github.dadiyang.httpinvoker.util.ParamUtils; |
9 | 10 | import org.slf4j.Logger; |
@@ -34,7 +35,7 @@ public class ResultBeanResponseProcessor implements ResponseProcessor { |
34 | 35 | private Map<Class<?>, Boolean> isResultBeanCache = new ConcurrentHashMap<Class<?>, Boolean>(); |
35 | 36 |
|
36 | 37 | @Override |
37 | | - public Object process(HttpResponse response, Method method) { |
| 38 | + public Object process(HttpResponse response, Method method) throws UnexpectedResultException { |
38 | 39 | // 对返回值进行解析,code 为 0,则返回反序列化 data 的值,否则抛出异常 |
39 | 40 | String rs = response.getBody(); |
40 | 41 | // 以下几种情况下,无需解析响应 |
@@ -72,9 +73,8 @@ public Object process(HttpResponse response, Method method) { |
72 | 73 | String uri = req != null ? req.value() : method.getName(); |
73 | 74 | // 兼容两种错误信息的写法 |
74 | 75 | String errMsg = obj.containsKey(MESSAGE) ? obj.getString(MESSAGE) : obj.getString(MSG); |
75 | | - String msg = "请求api失败, uri: " + uri + ", 错误信息: " + errMsg; |
76 | | - log.warn(msg); |
77 | | - throw new IllegalStateException(msg); |
| 76 | + log.warn("请求api失败, uri: " + uri + ", 错误信息: " + errMsg); |
| 77 | + throw new UnexpectedResultException(errMsg); |
78 | 78 | } |
79 | 79 | } |
80 | 80 |
|
@@ -149,9 +149,9 @@ private Field[] getDeclaredFields(Class<?> returnType) { |
149 | 149 | } else { |
150 | 150 | List<Field> fields = new ArrayList<Field>(); |
151 | 151 | Class<?> type = returnType; |
152 | | - while (type != Object.class && !type.isInterface()) { |
| 152 | + while (type != null && type != Object.class && !type.isInterface()) { |
153 | 153 | fields.addAll(Arrays.asList(type.getDeclaredFields())); |
154 | | - type = returnType.getSuperclass(); |
| 154 | + type = type.getSuperclass(); |
155 | 155 | } |
156 | 156 | return fields.toArray(new Field[]{}); |
157 | 157 | } |
|
0 commit comments