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

Expose error codes in exceptions (502 Bad Gateway) #20

Closed
keeakita opened this issue Nov 6, 2015 · 2 comments
Closed

Expose error codes in exceptions (502 Bad Gateway) #20

keeakita opened this issue Nov 6, 2015 · 2 comments

Comments

@keeakita
Copy link
Contributor

keeakita commented Nov 6, 2015

Right now there doesn't appear to be a good way to tell specifically what error code Telegram returns in the case of an error, other than looking at the string coming from Telegram::Bot::Exceptions::ResponseError. This approach seems kind of fragile. It would be nice it exposed the numeric code.

My use case for this is that once in a while the Telegram API returns a 502, which is just some temporary gateway error. I'd like my bot to restart itself in this case, but not if the error is a 4xx as it indicates the bot did something wrong and should stop.

I can submit a pull request that implements this, but I was wondering what the best way of doing this is. I could:

  1. Expose the data method that is currently private. This would allow objects to inspect the actual response and take actions based on it. This might have design implications.
  2. Expose a new method, error_code that contains only the error code.
  3. Raise a specific error type for each known Telegram response (one for 409, one for 502, etc). It'd be a lot of new classes.
  4. Code the bot by default to keep trying in case of 502 or even 5xx errors, instead of throwing an exception. This is what the Golang telegram bindings do.

I'm curious to what your thoughts are on this. Like I said, I'm happy to take this and work on it, just want to make sure I'm going in the right direction.

@atipugin
Copy link
Owner

atipugin commented Nov 6, 2015

@oslerw to be honest, you can access error code through response attribute (which is an instance of HTTParty::Response). But it smells bad (as end user shouldn't care about gem internals) and we definitely need to expose code as attribute. So, second option is a way to go.

@keeakita
Copy link
Contributor Author

Fixed in 3f566b8

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