Retrofit response.errorBody() is null Retrofit response.errorBody() is null json json

Retrofit response.errorBody() is null


As I have commented, you should use String s = response.errorBody().string(); then Log.i("David", "Incorrect response: "+ s; and jsonError = new JSONArray(s);. Don't call response.errorBody().string() twice.

If you try/catch IllegalStateException or Exception you will get info look like the following at logcat

W/System.err: java.lang.IllegalStateException: closedW/System.err:     at com.squareup.okhttp.internal.http.HttpConnection$FixedLengthSource.read(HttpConnection.java:415)W/System.err:     at okio.Buffer.writeAll(Buffer.java:956)W/System.err:     at okio.RealBufferedSource.readByteArray(RealBufferedSource.java:92)W/System.err:     at com.squareup.okhttp.ResponseBody.bytes(ResponseBody.java:57)W/System.err:     at com.squareup.okhttp.ResponseBody.string(ResponseBody.java:83)

Hope it helps!