Help me out. I am using retrofit for my project and I am totally new on it. I am getting the following error. Why I am getting a false response?
2020-02-20 15:35:26.230 22602-22602/q.goaldiggers.auth_api_testing
D/Ayush: Response
2020-02-20 15:35:26.230 22602-22602/q.goaldiggers.auth_api_testing
D/Ayush:
Response{protocol=http/1.1, code=402, message=Payment Required,
url=https://quizziyapa.herokuapp.com/getTopics}
2020-02-20 15:35:26.230 22602-22602/q.goaldiggers.auth_api_testing
D/Ayush: Payment Required
2020-02-20 15:35:26.230 22602-22602/q.goaldiggers.auth_api_testing
D/Ayush: okhttp3.ResponseBody$1@647c751
2020-02-20 15:35:26.230 22602-22602/q.goaldiggers.auth_api_testing
D/Ayush: null
2020-02-20 15:35:26.230 22602-22602/q.goaldiggers.auth_api_testing
D/Ayush: false
2020-02-20 15:35:26.230 22602-22602/q.goaldiggers.auth_api_testing
D/Ayush: retrofit2.OkHttpCall$NoContentResponseBody@4f0bbb6
[Error][1]
JSON Structure
This is my json structure.
{
"topics": [
{
"_id": 2,
"topic": "abc",
"imageUrl": "abc12345"
},
{
"_id": 3,
"topic": "abc",
"imageUrl": "abc12345"
}
]
}
Topic.java
My Model class
public class Topic {
int _id;
String topic;
String imageUrl;
public Topic(int _id, String topic, String imageUrl) {
this._id = _id;
this.topic = topic;
this.imageUrl = imageUrl;
}
public int getId() {
return _id;
}
public String getTopic() {
return topic;
}
public String getImageUrl() {
return imageUrl;
}
}
TopicResponse.java
JSON response class
public class TopicResponse {
@SerializedName("topics")
Topic[] topics;
public TopicResponse(Topic[] topics) {
this.topics = topics;
}
public Topic[] getTopics() {
return topics;
}
}
IUserApi.java (API Interface)
public interface IUserApi {
@GET("getTopics")
Call<TopicResponse> getTop();
}
MainActivity.java
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://quizziyapa.herokuapp.com/")
.addConverterFactory(GsonConverterFactory.create())
.build();
IUserApi api = retrofit.create(IUserApi.class);
Call<TopicResponse> call= api.getTop();
call.enqueue(new Callback<TopicResponse>() {
@Override
public void onResponse(Call<TopicResponse> call, Response<TopicResponse> response) {
Log.d("Ayush", "Response");
Log.d("Ayush", String.valueOf(response));
Log.d("Ayush", String.valueOf(response.message()));
Log.d("Ayush", String.valueOf(response.errorBody()));
Log.d("Ayush", String.valueOf(response.body()));
Log.d("Ayush", String.valueOf(response.isSuccessful()));
Log.d("Ayush", String.valueOf(response.raw().body()));
}
@Override
public void onFailure(Call<TopicResponse> call, Throwable t) {
Log.d("Ayush", "Failed \n"+t.getMessage());
}
});
Help me out what should I do to solve this issue?