Ervie/jikan.net

Error Handling for Get Methods

Closed this issue · 2 comments

Is there any possible error handling for things like GetAnime? for example the id 500 does not exist on MAL and I use Jikan.net for a discord bot I am currently coding but am having trouble trying to do some error handling when something, like I mentioned above, happens. This could be very niche but would be cool if there's some built-in error handling or if you could give me some tips on how to handle situations like that.

Ervie commented

I think it's up to the user to decide what to do in a situation when the error is encountered - by default all the errors are thrown to the upper level so the user can catch and decide if they want to retry based on error code. Some of them indicate that retrying is won't work, for example non existent id that you mention (it will throw JikanRequestException with StatusCode 404). No the other hand you might met status error 429, meaning there are too many request at once coming from you bot - you might want to wait a little bit and retry the call.

On the other hand wrapper has built-in error supression. You just pass second parameter in a constructor like this:
var jikan = new Jikan(true, true)
Now every failed result will be returned as null and you just perform a null check. But I would still suggest using try catch: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/try-catch

Sorry, still new at debugging and learning and really didn't understand how to use Try/Catch. Figured it out.