Computer/Android&iOS

(Android) Okhttp3 + retrofit 2 > illegalStateException: closed

ywlee 2019. 4. 26. 16:18

로깅을 위해 interceptor 에 response.body().string(); 를 걸어놓은것이 문제였다.

 

https://github.com/square/okhttp/issues/1240

 

java.lang.IllegalStateException: closed when trying to access response in onResponse(Response response) · Issue #1240 · square/o

I get java.lang.IllegalStateException: closed at com.squareup.okhttp.internal.http.HttpConnection$FixedLengthSource.read(HttpConnection.java:455) at okio.Buffer.writeAll(Buffer.java:594) at okio.Re...

github.com

 

를 보면, string() 을 두번 호출하지 말라는것.

 

아마 내부적으로 string() 을 한ㄴ번 호출하나보다. 

 

로그를 찍을때만 활성화 시켜놓고 나머지는 주석처리하자.