Java Application exits if calling PokeAPI with invalid argument
See original GitHub issueDear 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!
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (5 by maintainers)
I just confirmed that all 293 abilities are reachable.
We should probably return something more informative than 404 in case of rate limiting
On Thu, Apr 18, 2019 at 16:47 Kronopt notifications@github.com wrote: