title: Need to get the response message, while getting 400 error in Retrofit, Android
body: <p>I'm getting the following response, while 400 error occurs.</p>
  <pre><code>  {&quot;unit&quot;:&quot;You may not create job for other than your unit!&quot;}
  
      2021-06-08 17:15:33.715 8599-8752/com.fyxtpmtenant I/okhttp.OkHttpClient: &lt;-- 400 https://myserver.com/v1/jobs/ (131ms)
  2021-06-08 17:15:33.715 8599-8752/com.fyxtpmtenant I/okhttp.OkHttpClient: date: Tue, 08 Jun 2021 11:45:35 GMT
  2021-06-08 17:15:33.715 8599-8752/com.fyxtpmtenant I/okhttp.OkHttpClient: content-type: application/json
  2021-06-08 17:15:33.715 8599-8752/com.fyxtpmtenant I/okhttp.OkHttpClient: content-length: 59
  2021-06-08 17:15:33.715 8599-8752/com.fyxtpmtenant I/okhttp.OkHttpClient: server: nginx/1.18.0 (Ubuntu)
  2021-06-08 17:15:33.715 8599-8752/com.fyxtpmtenant I/okhttp.OkHttpClient: vary: Accept, Origin
  2021-06-08 17:15:33.715 8599-8752/com.fyxtpmtenant I/okhttp.OkHttpClient: allow: GET, POST, HEAD, OPTIONS
  2021-06-08 17:15:33.715 8599-8752/com.fyxtpmtenant I/okhttp.OkHttpClient: x-frame-options: DENY
  2021-06-08 17:15:33.715 8599-8752/com.fyxtpmtenant I/okhttp.OkHttpClient: x-content-type-options: nosniff
  2021-06-08 17:15:33.715 8599-8752/com.fyxtpmtenant I/okhttp.OkHttpClient: referrer-policy: same-origin
  2021-06-08 17:15:33.716 8599-8752/com.fyxtpmtenant I/okhttp.OkHttpClient: {&quot;unit&quot;:&quot;You may not create job for other than your unit!&quot;}
  2021-06-08 17:15:33.716 8599-8752/com.fyxtpmtenant I/okhttp.OkHttpClient: &lt;-- END HTTP (59-byte body)
  </code></pre>
  <p>I need to show as an alert to the user, what ever I get in the 400 error response. The response may change. I tried the following</p>
  <pre><code> JSONObject msgObj = new JSONObject(String.valueOf(response.raw()));
  </code></pre>
  <p>But get the following error</p>
  <pre><code>org.json.JSONException: Value Response of type java.lang.String cannot be converted to JSONObject
  </code></pre>
  <p><strong>Edit:</strong>
  I tried the following to get the response:</p>
  <pre><code> Log.e(&quot;error body 1&gt;&quot;,response.errorBody()+&quot; &quot;);
    Log.e(&quot;error body 2&gt;&quot;,response.body()+&quot; &quot;);
    Log.e(&quot;error body 3&gt;&quot;,response.toString()+&quot; &quot;);
    Log.e(&quot;error body 4&gt;&quot;,response.message()+&quot; &quot;);
    Log.e(&quot;error body 8&gt;&quot;,response.raw()+&quot; &quot;);
  </code></pre>
  <p>And got this:</p>
  <pre><code>error body 1&gt;: okhttp3.ResponseBody$Companion$asResponseBody$1@d2d0fcc 
  error body 2&gt;: null 
  error body 3&gt;: Response{protocol=h2, code=400, message=, url=https://c1.myserver.com/v1/jobs/} 
  error body 4&gt;:  
  error body 8&gt;: Response{protocol=h2, code=400, message=, url=https://c1.myserver.com/v1/jobs/} 
  </code></pre>