Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java Application exits if calling PokeAPI with invalid argument #66

Closed
Adrian-26-Isotope opened this issue Apr 18, 2019 · 5 comments
Closed
Labels

Comments

@Adrian-26-Isotope
Copy link

Dear Developers,

I am facing a usability problem when using pokekotlin.
This is my situation:
I am writing a Java application and want to cache all abilities. My first intention was to call getAbility() until I get no more abilities:

        boolean continueLoop = true;
        for (int i = 1; continueLoop; i++) {
            Ability ability = pokeApi.getAbility(i);
            if (ability == null) {
                continueLoop = false;
            }
            else {
                //do somthing
            }
        }

However as soon as i reaches a value PokeAPI returns a 404 for, my application exits with this exception:

Exception in thread "main" me.sargunvohra.lib.pokekotlin.client.ErrorResponse: (404) Not Found
at me.sargunvohra.lib.pokekotlin.client.PokeApiClient.result(PokeApiClient.kt:13)
at me.sargunvohra.lib.pokekotlin.client.PokeApiClient.getAbility(PokeApiClient.kt:251)

I tried to catch the exception. This didn't work.
My next thought was to use the method getAbilityList(). This is working for me, but to get the actual Ability object I have to extract the id from the NamedApiResource and then do the getAbility() call with this id. This approach works but, I assume, PokeAPI is called twice for every ability. I would prefer not doing so.

I don't know nothing about kotlin and thus can't tell if this behaviour is intended or not. Also I have no idea how to prevent my application from exiting.

Wouldn't it be possible to just return null in case a HTTP call returns no result/404 error?

Regards
Adrian

P.S.: Nevertheless you are doing a great job. Kudos to you!

@Kronopt
Copy link
Member

Kronopt commented Apr 18, 2019

By running that code you're just going over the 100 API requests per minute of pokeapi.co (https://pokeapi.co/docs/v2.html#info), as there are 293 abilities.

Please read the documentation. You shouldn't be scraping the API like that.

As for the error, that's probably the default error for a 404 http error.

@sargunv
Copy link
Member

sargunv commented Apr 19, 2019 via email

@tdmalone
Copy link
Member

Hmm yes... we should have a 429 instead of a 404. Having said that, I don't think we've actually got rate limiting enabled on the API at the moment (IIRC).

@sargunv
Copy link
Member

sargunv commented Apr 19, 2019

In that case the 404 is interesting, can we confirm all the abilities are reachable?

@Kronopt
Copy link
Member

Kronopt commented Apr 19, 2019

I just confirmed that all 293 abilities are reachable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants