title: Retrofit 2: responseBodyConverter converts to null object
body: <p>I'm using the latest (as of now 2.0.0-beta4) version of <a href="http://square.github.io/retrofit/" rel="nofollow noreferrer">Retrofit</a>. When receiving 200 OK code from server, everything is working fine. But I want to deal with not OK responses too, such as code 401. So, I have to get the error response code to figure out exactly what action to do and display appropriate data:</p>
  
  <pre><code>@Override
  public void onResponse(Call&lt;LoginResponse&gt; call, Response&lt;LoginResponse&gt; response) {
      if (response != null &amp;&amp; !response.isSuccess() &amp;&amp; response.errorBody() != null) {
          Converter&lt;ResponseBody, APIError&gt; errorConverter = retrofit.responseBodyConverter(APIError.class, new Annotation[0]);
          try {
              APIError error = errorConverter.convert(response.errorBody());
              Toast.makeText(getContext(), "code = " + error.getCode() + ", status = " + error.getStatus(), Toast.LENGTH_SHORT).show();
          } catch (IOException e) {
              e.printStackTrace();
          }
      } else if (null != response) {
          if (response.isSuccess()) {
              LoginResponse loginResponse = response.body();
              Toast.makeText(getContext(), "Successful login: " + loginResponse.getId(), Toast.LENGTH_SHORT).show();
          }
      }
  }
  </code></pre>
  
  <p><strong>APIError.java</strong></p>
  
  <pre><code>public class APIError {
      String name;
      int status;
      String message;
      int statusCode;
      String code;
      String stack;
  
      public String getName() {
          return name;
      }
  
      public int getStatus() {
          return status;
      }
  
      public String getCode() {
          return code;
      }
  }
  </code></pre>
  
  <p><strong>Server's error response</strong></p>
  
  <pre><code>{
    "error": {
      "name": "Error",
      "status": 401,
      "message": "login failed",
      "statusCode": 401,
      "code": "LOGIN_FAILED",
      "stack": "Error: login failed"
    }
  }
  </code></pre>
  
  <p>But <code>errorConverter.convert()</code> returns an object with null values. I've looked <a href="https://stackoverflow.com/questions/32519618/retrofit-2-0-how-to-get-deserialised-error-response-body">similar posts</a>, but it didn't help.</p>
  
  <p>What is wrong with the code?</p>