android - OkHttp interceptor - response already "consumed" android - OkHttp interceptor - response already "consumed" android android

android - OkHttp interceptor - response already "consumed"


I just had the same problem myself, and the solution I found was to consume the response's body and build a new response with a new body. I did it like so:

...Response response = chain.proceed(request);MediaType contentType = response.body().contentType();String bodyString = response.body().string();if (tokenExpired(bodyString)) {    // your logic here...}ResponseBody body = ResponseBody.create(contentType, bodyString);return response.newBuilder().body(body).build();