Skip to content

Commit db8820f

Browse files
committed
modify ResponseWrapper setErrorObject add exception process
1 parent a132d9c commit db8820f

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/main/java/cn/jpush/api/common/connection/NativeHttpClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ private ResponseWrapper _doRequest(String url, String content,
206206
break;
207207
case 403:
208208
LOG.error("Request is forbidden! Maybe your appkey is listed in blacklist or your params is invalid.");
209-
// wrapper.setErrorObject();
209+
wrapper.setErrorObject();
210210
break;
211211
case 410:
212212
LOG.error("Request resource is no longer in service. Please according to notice on official website.");

src/main/java/cn/jpush/api/common/resp/ResponseWrapper.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package cn.jpush.api.common.resp;
22

3+
import com.google.gson.JsonElement;
4+
import com.google.gson.JsonSyntaxException;
35
import org.slf4j.Logger;
46
import org.slf4j.LoggerFactory;
57

@@ -35,7 +37,22 @@ public void setRateLimit(String quota, String remaining, String reset) {
3537
}
3638

3739
public void setErrorObject() {
38-
error = _gson.fromJson(responseContent, ErrorObject.class);
40+
try {
41+
error = _gson.fromJson(responseContent, ErrorObject.class);
42+
} catch (JsonSyntaxException e) {
43+
int index = responseContent.indexOf("error");
44+
if( -1 != index ) {
45+
int from = responseContent.indexOf("{", index);
46+
int to = responseContent.indexOf("}", from);
47+
String errorStr = responseContent.substring(from, to + 1);
48+
error = new ErrorObject();
49+
try {
50+
error.error = _gson.fromJson(errorStr, ErrorEntity.class);
51+
} catch (JsonSyntaxException e1) {
52+
LOG.error("unknown response content:" + responseContent, e);
53+
}
54+
}
55+
}
3956
}
4057

4158
public boolean isServerResponse() {

0 commit comments

Comments
 (0)