title: Retrofit connection failure returns RetrofitError.response as null
body: <p>Using Retrofit 1.6.0, OkHTTP 2.0.0, and OkHTTP-UrlConnection 2.0.0.</p>
  
  <p>I am doing a POST to a service using Retrofit to a URL that does not exist. The failure callback is called, as expected. However, the RetrofitError parameter does not have a response. I would really like to grab the HTTP status code that was returned by using</p>
  
  <pre><code>error.getResponse().getStatus()
  </code></pre>
  
  <p>but since getResponse() returns null, I can't.</p>
  
  <p>Why is getResponse() null and how can I get the status?</p>
  
  <p>Thanks.</p>
  
  <p>Also, the error I am receiving is UnknownHostException, as expected. Repeat: I am expecting this error. I want to know how to get the HTTP status code or why error.getResponse() returns null.</p>
  
  <p>Edit: Here's some code:</p>
  
  <pre><code>RestAdapterBuilderClass.java
      RestAdapter restAdapter = new RestAdapter.Builder()
              .setEndpoint("http://badURL.DoesntMatter/");
              .setRequestInterceptor(sRequestInterceptor)
              .setLogLevel(RestAdapter.LogLevel.FULL)
               .build();
      sService = restAdapter.create(ServiceInterface.class);
  
  ServiceInterface.java
      @POST("/Login")
      void login(@Body JsonObject body, Callback&lt;String&gt; callback);
  
  CallbackClass.java
      @Override
      public void failure(RetrofitError error) {
          if (error.getResponse() == null) {
  
              // error.getResponse() is null when I need to get the status code
              // from it.
  
              return;
          }
      }
  </code></pre>