title: How to handle error response with Retrofit 2?
body: <p>How to handle error response with Retrofit 2 using <strong>synchronous</strong> request?</p>
  
  <p>I need process response that in normal case return pets array and if request has bad parametrs return error json object. How can I process this two situations?</p>
  
  <p>I am trying to use <a href="https://futurestud.io/tutorials/retrofit-2-simple-error-handling" rel="noreferrer">this</a> tutorial but the main problem is mapping normal and error json to objects. </p>
  
  <p>My <strong>normal response</strong> example:</p>
  
  <pre><code>[ {
      "type" : "cat",
      "color": "black"
  }, 
  {
      "type" : "cat",
      "color": "white"
  } ]
  </code></pre>
  
  <p><strong>Error response</strong> example:</p>
  
  <pre><code>{"error" = "-1", error_description = "Low version"}
  </code></pre>
  
  <p>What I got:</p>
  
  <pre><code>    Call&lt;List&lt;Pet&gt;&gt; call = getApiService().getPet(1);
      Response&lt;List&lt;Pet&gt;&gt; response;
      List&lt;Pet&gt; result = null;
  
      try {
          response = call.execute(); //line with exception "Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path"
          if(!response.isSuccessful()){
              Error error = parseError(response);
              Log.d("error message", error.getErrorDescription());
          }
          if (response.code() == 200) {
              result = response.body();
          }
      } catch (IOException e) {
          e.printStackTrace();
      }
  </code></pre>