title: How to get Retrofit error message in android?
body: <pre><code> &lt;-- 401 Unauthorized http://172.20.20.128/api/v1/login (126ms)
      D/OkHttp: Date: Tue, 19 Sep 2017 12:55:29 GMT
      D/OkHttp: Server: Apache/2.4.12 (Unix) OpenSSL/1.0.1m PHP/5.5.24 mod_perl/2.0.8-dev Perl/v5.16.3
      D/OkHttp: X-Powered-By: PHP/5.5.24
      D/OkHttp: Set-Cookie: PHPSESSID=bl0brh2n6pr1sbp76kf95q8um1; path=/; HttpOnly
      D/OkHttp: Expires: Thu, 19 Nov 1981 08:52:00 GMT
      D/OkHttp: Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
      D/OkHttp: Pragma: no-cache
      D/OkHttp: Set-Cookie: language=26fb26f386223e2e177900bfa422048f6e2e5367s%3A5%3A%22en_us%22%3B; expires=Thu, 28-Dec-2017 12:55:29 GMT; Max-Age=8640000; path=/
      D/OkHttp: Content-Length: 68
      D/OkHttp: Keep-Alive: timeout=5, max=100
      D/OkHttp: Connection: Keep-Alive
      D/OkHttp: Content-Type: application/json
      D/OkHttp: {"error":true,"code":"401","message":"Invalid username or password"}
      D/OkHttp: 
      &lt;-- END HTTP (68-byte body)
  </code></pre>
  
  <p>Above is the log showing in android monitor. I want to get following message that is showing in the above Log detail. </p>
  
  <pre><code>{"error":true,"code":"401","message":"Invalid username or password"}
  </code></pre>
  
  <p>This is my Request</p>
  
  <pre><code>  call.validateUser(request)
              .subscribeOn(Schedulers.io())
              .observeOn(AndroidSchedulers.mainThread())
              .subscribe(new Subscriber&lt;Response&lt;LoginResponse&gt;&gt;() {
                  @Override
                  public void onCompleted() {
                      AppLog.info("onCompleted", "onCompleted");
                  }
  
                  @Override
                  public void onError(Throwable e) {
                      AppLog.info("onError", new Gson().toJson(e));// not coming to onError. 
                  }
  
                  @Override
                  public void onNext(Response&lt;LoginResponse&gt; loginResponse) {
  
                      AppLog.info("code", "" + loginResponse.code()); // returns 401
                      AppLog.info("message", loginResponse.message()); // returns Unauthorized
                      LoginResponse response = loginResponse.body(); // returns null
                      AppLog.info("errorBody", new Gson().toJson(loginResponse.errorBody()));// returns null
                      AppLog.info("headers", new Gson().toJson(loginResponse.headers()));// returns header detail
                      AppLog.info("body", new Gson().toJson(loginResponse.body()));// returns null
  
  
                  }
              });
  </code></pre>
  
  <p>I checked with onError callback. it is also showing 401 Unauthorized message not the original error message.</p>