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

Error Handling for Get Methods #30

Closed
ProjektCode opened this issue Sep 6, 2021 · 2 comments
Closed

Error Handling for Get Methods #30

ProjektCode opened this issue Sep 6, 2021 · 2 comments

Comments

@ProjektCode
Copy link

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
Copy link
Owner

Ervie commented Sep 6, 2021

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

@ProjektCode
Copy link
Author

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

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

No branches or pull requests

2 participants