これは不正なチェックのためのインターセプタコードです。Log.e Interceptorで何らかの問題を作成しています
class UnauthorizedInterceptor implements Interceptor {
private Context context;
UnauthorizedInterceptor(Context context) {
this.context = context;
}
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
Response response = chain.proceed(request);
Log.e("response: ", response.body().string()); // creating problem
ObjectMapper objectMapper = new ObjectMapper();
ServerResponse serverResponse = objectMapper.readValue(response.body().string(), ServerResponse.class);
if (serverResponse.getErrorCode() == 401) {
throw new UnauthorizedException(R.string.unauthorized_user);
} else {
return response;
}
}
private class UnauthorizedException extends IOException {
UnauthorizedException(final int stringRes) {
super(context.getString(stringRes));
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
Toast.makeText(context, stringRes, Toast.LENGTH_SHORT).show();
}
});
}
}
}
私はその後、私はレトロフィット成功コールバックで任意の応答を取得していない午前インターセプタでLog.e
を使用している場合。しかし、Log.e
はlogcatの応答を適切に表示します。その後、Retrofitの成功コールバックにコールバックを与えません。エラーコールバックに戻り、IllegalStateException:closed
となります。
しかし、私がLog.e
のコードを傍受者にコメントアウトした場合、うまくいきます。
なぜそれが起こっているのですか?誰もこの事を説明してもらえますか?
ありがとうございます。
Log.eラインが壊れているようです。正しくコピーしてもよろしいですか? –
@AleksandrMedvedevが更新されました。申し訳ありませんが、私は括弧がstackoverflowで入力中に逃した。 –
あなたのLog.eは間違っています。あなたの場合** Log.e(TAG、 "response:" + response.body()。string()); ** –