title: Why i am getting null if response in not success in response android retrofit API?
body: <p>My problem is that when response is successful, i am getting response. But if response is not success, I am not getting any response in body, it's null. In case of any error like 404, 500 response is null. I am a beginner.</p>
  <p><a href="https://i.stack.imgur.com/9AQp3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9AQp3.png" alt="enter image description here" /></a></p>
  <pre><code>void sendMessage(){
      String user_id = sessionManager.getPreferences(getActivity(), &quot;user_id&quot;);
      String message = binding.inputMessage.getText().toString();
      String api_key = &quot;954f011a-ab85-42e&quot;;
      String secret_key = &quot;v7FTQC&amp;Cppbukk&quot;;
      if (message.isEmpty()){
          binding.inputMessage.setError(&quot;Please write your message&quot;);
          binding.inputMessage.requestFocus();
      }else {
          binding.inputMessage.setError(null);
  
          APIService service = RetrofitInstance.getRetrofitInstance().create(APIService.class);
          Call&lt;ContactUsModel&gt; call = service.sendMessage(user_id, message, api_key, secret_key);
          progressDialog.setMessage(&quot;Sending&quot;);
          progressDialog.show();
          call.enqueue(new Callback&lt;ContactUsModel&gt;() {
              @Override
              public void onResponse(Call&lt;ContactUsModel&gt; call, Response&lt;ContactUsModel&gt; response) {
                  progressDialog.dismiss();
                  ContactUsModel model = response.body();
                  if (response.code() == 201){
                      if (model.getSuccess() == 1){
                          binding.inputMessage.setText(&quot;&quot;);
                          Toast.makeText(getActivity(), model.getMessage(), Toast.LENGTH_SHORT).show();
                      }
  
                  }else{
                     //Toast.makeText(getActivity(), response.body().toString(), Toast.LENGTH_SHORT).show();
                      Log.e(&quot;responcebody&quot; , response.body().toString());
                  }
  
              }
  
              @Override
              public void onFailure(Call&lt;ContactUsModel&gt; call, Throwable t) {
                  progressDialog.dismiss();
                  Toast.makeText(getActivity(), t.getMessage(), Toast.LENGTH_SHORT).show();
  
              }
          });
      }
  }
  </code></pre>
  <p><strong>My Model is below in which i am getting responce, parameters name are totally correct</strong></p>
  <pre><code>            package com.example.miinterest.model;
          
          import com.google.gson.annotations.SerializedName;
          
          public class ContactUsModel {
              @SerializedName(&quot;success&quot;) private int success;
              @SerializedName(&quot;message&quot;) private String message;
          
              public int getSuccess() {
                  return success;
              }
          
              public void setSuccess(int success) {
                  this.success = success;
              }
          
              public String getMessage() {
                  return message;
              }
          
              public void setMessage(String message) {
                  this.message = message;
              }
          }
  </code></pre>
  <p><strong>And Api Call Method. I created a method and calling API from here</strong></p>
  <pre><code>               @FormUrlEncoded
              @POST(&quot;addContactUsQuery&quot;)
              Call&lt;ContactUsModel&gt; sendMessage(
                      @Field(&quot;user_id&quot;) String user_id,
                      @Field(&quot;message&quot;) String message,
                      @Header(&quot;api_key&quot;) String api_key,
                      @Header(&quot;secret_key&quot;) String secret_key
              );
  </code></pre>