我定制了一个拦截器,以便在其过期时刷新令牌。当我得到response body来检测token是否过期时,它会抛出java.lang.IllegalStateException:closed。OkHttp 3 IllegalStateException
这里是我的代码以OkHttp 3
@Override
public Response intercept(Chain chain) throws IOException {
Request original = chain.request();
Request.Builder requestBuilder = original.newBuilder()
.header("Content-Type", "application/json")
.header(Constants.TAG_AUTHORIZATION, "Bearer " + token)
.method(original.method(), original.body());
Request request = requestBuilder.build();
Response response = chain.proceed(request);
if (response.code() == 200) {
String json = response.body().string();
try {
JSONObject obj = new JSONObject(json);
int code = obj.getInt(Constants.TAG_CODE);
if (code == Constants.REQUEST_CODE_TOKEN_EXPIRED) {
Response r = makeTokenRefreshCall(request, chain);
return r;
}
} catch (JSONException e) {
e.printStackTrace();
}
}
return response;
}
请帮帮我!
什么是例外?显示logcat – matrix
@matrix异常不是在拦截()中抛出,而是在我的RxJava onError()方法中。 –