0

I have an Android app that has this particular retrofit code that has not been touched in years. All of a sudden we started seeing 404 errors when making certain GET calls. When debugging through it, looking at the response, it looks like this:

Response{protocol=h2, code=404, message=, url=https://www.mainstreetartsfest.org/feed/artist/getAllCategories}

When I copy that URL into a browser, it loads the data fine. We are doing something similar on iOS with no issues, but on Android, it's failing now. I am completely stumped as to any reasons why this would have started occurring. Any ideas? The interface for the Retrofit API looks like this:

@GET("feed/artist/getAllCategories")
Call<List<Category>> getAllCategories();

Our base URL is defined as follows:

public static final String BASE_URL = "http://www.mainstreetartsfest.org/";

Let me know if more info is needed.

Martin Zeitler
  • 1
  • 19
  • 155
  • 216
svguerin3
  • 2,433
  • 3
  • 29
  • 53
  • 1
    not sure if that's the source of the issue, but `BASE_URL` is http instead of https – vlatkozelka Apr 12 '19 at 00:50
  • Good catch on that! I'm not sure why it was showing up in the debugger as https, but even when I switched it over to https in the BASE_URL, it still has the same 404 error. :( – svguerin3 Apr 12 '19 at 00:52
  • another thing I noticed by sending a GET with postman, is that the response is always 404 status, yet it returns data properly. Probably a problem on your backend, setting the status to 404 instead of 200? – vlatkozelka Apr 12 '19 at 00:54
  • the server indeed sends out the wrong status-code. just parse on `HTTP404`... or notify them. – Martin Zeitler Apr 12 '19 at 01:14

2 Answers2

1

I have try this api on postman and this api is giving 404 Not Found. my backhand team says that there is some mistake in backhand side .

Sandeep Malik
  • 1,972
  • 1
  • 8
  • 17
0

Something alike this should work - and won't break once they've fixed the problem on their side:

Call<Categories> api = SomeClient.getAllCategories();
api.enqueue(new Callback<Categories>() {
    @Override
    public void onResponse(@NonNull Call<Categories> call, @NonNull Response<Categories> response) {
        switch(response.code()) {

            /* temporary workaround: treating HTTP404 as if it would be HTTP200. */
            case 200:
                Log.e(LOG_TAG, "a proper HTTP200 header had been received.");
            case 404:
                if (response.body() != null) {
                    Categories items = response.body();
                    ...
                } else if (response.errorBody() != null) {
                    String errors = response.errorBody().string();
                    ...
                }
                break;
        }
    }
}

Just logging an error on HTTP200, so that one can see when it's about time to fix the code.

Martin Zeitler
  • 1
  • 19
  • 155
  • 216
  • Thank you for putting this together. Unfortunately response.body() is null, so this fails as well. :( – svguerin3 Apr 12 '19 at 01:37
  • @svguerin3 you might be lacking the annotations on your model `List` or `Categories`, as I've called it. use [jsonschema2pojo](http://www.jsonschema2pojo.org/) to generate the according `POJO` from `JSON`, which can parse that response. the GSON converter is also required in order to process JSON responses. – Martin Zeitler Apr 12 '19 at 01:40
  • this [example](https://stackoverflow.com/a/53082050/549372) might be helpful, because that array does not feature a name (it's invalid syntax). therefore the `.setLenient()` is required. manually parsing the response would be the other option. – Martin Zeitler Apr 12 '19 at 01:50