question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Java Application exits if calling PokeAPI with invalid argument

See original GitHub issue

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!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Kronoptcommented, Apr 19, 2019

I just confirmed that all 293 abilities are reachable.

1reaction
sargunvcommented, Apr 19, 2019

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:

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.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/PokeAPI/pokekotlin/issues/66#issuecomment-484725040, or mute the thread https://github.com/notifications/unsubscribe-auth/AAKCLJK55RT2E2H3HMBKXJ3PREB7RANCNFSM4HHA5JVA .

Read more comments on GitHub >

github_iconTop Results From Across the Web

Invalid Argument on API Call?
My impression is that is not a valid offer, and you need to use a web rtc client to create it. See webrtc.org...
Read more >
Documentation - PokéAPI
Calling any API endpoint without a resource ID or name will return a paginated list of available resources for that API. By default,...
Read more >
[Solved]-How can I use Mockito to test this function?-kotlin
@Test fun `should invoke reveal permission on PermissionApi when type is REVEAL_NOW`(){ val mockPermissionApi = mock(PermissionApi::class.java) val ...
Read more >
[2016-10-24] Challenge #289 [Easy] It's super effective!
Use the Pokémon api to calculate the output damage. Like http://pokeapi.co/api/v2/type/fire/. returns (skipped the long list) { "name ...
Read more >
Download Object Oriented Python Tutorial (PDF Version)
Python, an Object Oriented programming (OOP), is a way of programming that focuses on using objects and classes to design and build applications.....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found