How to get http message of any response in Retrofit/Okhttp for example Http code
201 -> Created,
400 -> Bad Request,
401 -> Unauthorized,
404 -> Not found
I want to show error message or success message base on these http code.
I have try get
response.message()
response.errorBody()
but not get what I want
CodePudding user response:
You need to provide more detail on how are you performing network calls. I'm guessing retrofit is what you are using. If thats the case, this works fine:
@Override
public void onResponse(Call<YourModel> call, Response<YourModel> response) {
if (response.code() == 200, 400, 401, 404) {
}
}
CodePudding user response:
Check this for catching various http status codes. https://futurestud.io/tutorials/retrofit-2-catch-server-errors-globally-with-response-interceptor