title: retrofit - get response error in string
body: <p>I am using retrofit to consume my REST api.</p>
  
  <p>I keep getting <code>400 bad request</code> from my server, and I can't parse the error to a string.</p>
  
  <p>When I tried to POST from <strong>POSTMAN</strong> chrome application, the request is successful and I get <code>201 created</code> response (new user).</p>
  
  <p><strong>here are my dependencies:</strong></p>
  
  <pre><code>compile 'com.google.code.gson:gson:2.4'
  compile 'com.squareup.retrofit:retrofit:2.0.0-beta2'
  compile 'com.squareup.retrofit:converter-gson:2.0.0-beta2'
  compile 'com.squareup.okhttp:okhttp:2.7.0'
  </code></pre>
  
  <p><strong>here is my interface:</strong></p>
  
  <pre><code>public interface PingMeApi {
  
      @Headers({"Content-Type: application/json", "Accept: text/html"})
      @POST("/users/")
      Call&lt;User&gt; createUser(@Body User user);
  
  }
  </code></pre>
  
  <p><strong>here is my POST request:</strong></p>
  
  <pre><code>Call&lt;User&gt; call = pingMeApplication.apiService.createUser(user);
  call.enqueue(new Callback&lt;User&gt;() {
      @Override
      public void onResponse(Response&lt;User&gt; response, Retrofit retrofit) {
          /// How can I parse the response here????
  
          String result;
          try {
              result = response.errorBody().string();
          } catch (IOException e) {
              e.printStackTrace();
          }
      }
  
      @Override
      public void onFailure(Throwable t) {
  
  
      }
  }
  </code></pre>
  
  <p>I can't seem to parse the response on <code>onResponse</code> so I cant understand what the error is.</p>
  
  <p>it says on the docs - <a href="http://inthecheesefactory.com/blog/retrofit-2.0/en" rel="nofollow">http://inthecheesefactory.com/blog/retrofit-2.0/en</a> that if I get and error, <code>onResponse</code> will be called and I can see the error string in <code>response.errorBody().string()</code>, but its an empty string.</p>
  
  <p>any ideas??</p>