title: Android Retrofit: response.errorBody is not null but response.errorBody.string() returns null
body: <p>I want to log the error message when the API call returns bad request or status code = 400</p>
  
  <p>I am doing this</p>
  
  <pre><code>call.enqueue(new Callback() {
          @Override
          public void onResponse(Call call, Response response) {
              if(response.isSuccessful()){
                  Log.e(TAG, "onResponse: "+response.message() );
                  Toast.makeText(RegisterCanister.this, "Registered Successfully!", Toast.LENGTH_SHORT).show();
              }
              else {
                      try {
                      Log.e(TAG, "onResponse: "+response.errorBody().string() );
                  } catch (IOException e) {
                      e.printStackTrace();
                  }
  
  
              }
          }
  
          @Override
          public void onFailure(Call call, Throwable t) {
              Toast.makeText(RegisterCanister.this, "Inhaler Registration Failed", Toast.LENGTH_SHORT).show();
          }
      });
  </code></pre>
  
  <p>The above code gets into the else condition as the response code is 400 where the response.errorBody is not null but I am not able to get the response of it. I tried using a converter and also JSONObject, faced the same issue. Wasn't able to extract the info from the errorBody()</p>
  
  <pre><code>Log.e(TAG, "onResponse: "+response.errorBody().string() );
  </code></pre>
  
  <p>logs</p>
  
  <pre><code>E/RegisterCanister: onResponse:
  </code></pre>
  
  <p>but</p>
  
  <pre><code>Log.e(TAG, "onResponse: "+response.errorBody());
  </code></pre>
  
  <p>logs</p>
  
  <pre><code>E/RegisterCanister: onResponse: okhttp3.ResponseBody$1@a33dda6
  </code></pre>
  
  <p>my error response is like this when trying in postman.</p>
  
  <pre><code>{"error":"Device not found"}
  </code></pre>