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

Add error handling examples #38

Open
gertvdijk opened this issue Jan 16, 2021 · 1 comment
Open

Add error handling examples #38

gertvdijk opened this issue Jan 16, 2021 · 1 comment

Comments

@gertvdijk
Copy link
Contributor

I would appreciate some examples how basic error handling is supposed to work with Peony in the docs & and code examples in examples/. I noticed somewhat more advanced error handling in the section Handle errors for every request, though, but I think that should remain a separate section.

For example: API error on user lookup (suspended account or user does not exist).

For context see my trial-and-error in #37. I'm more than happy to contribute some examples once I understand this a bit better. 😄

@odrling
Copy link
Owner

odrling commented Jan 16, 2021

For error handling try: ... except: would most likely be fine for most use cases. PeonyException is the parent class of all the errors that Peony will raise. One thing to keep in mind (at least when using the master branch or a future release) the errors that are related to HTTP error codes should be the latest to be caught so that you don't override the behaviour you defined for a more specific Twitter error. For now it's mostly described in #32 from back when I made this change but that should eventually end up in the documentation too. It would be great to have more examples featuring more complete error handling.

I don't think many users will find a use for error handlers, although that would be interesting to see and maybe even worth being featured in the documentation or as part the library if it makes sense for some use cases. It could also have some very specific uses, maybe in a graphical application you could use that to show a generic notification when an error is encountered.
The default error handler takes care of rate limits and server unavailability and retries the requests according to recommendations from Twitter (It should still be somewhere in the API documentation).
At some point I wanted to turn Peony into a library that could be used with any REST API, so that would have been helpful for that too.

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