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

Twitter::Error.errors lists descendants recursively #440

Closed
wants to merge 1 commit into from

Conversation

pengwynn
Copy link
Collaborator

While stealing borrowing the improved client/server exception handling approach for Octokit.rb, I noticed that Twitter::Error.errors throws an exception:

>> Twitter::Error.errors
NameError: uninitialized constant Twitter::Error::ClientError::HTTP_STATUS_CODE
        from /Users/wynn/.coral/repos/twitter@sferik/lib/twitter/error.rb:20:in `block in errors'
        from /Users/wynn/.coral/repos/twitter@sferik/lib/twitter/error.rb:19:in `each'
...

This change makes that method a bit more defensive and allows child error types to be listed recursively.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 9d904a1 on list-recursive-errors into * on master*.

@sferik
Copy link
Owner

sferik commented Aug 13, 2013

This introduces a bug with 403 errors, which should have the class Twitter::Error::Forbidden. After this patch, they will have the class Twitter::Error::AlreadyPosted, which subclasses Twitter::Error::Forbidden, so it has the same HTTP_STATUS_CODE constant.

Since client errors and server errors are not handled differently anymore, I may fix this by removing the Twitter::Error::ClientError and Twitter::Error::ServerError classes and have all error inherit directly from Twitter::Error, which would also solve this.

I’ve added this to the Version 5 milestone, so it will be resolved one way or the other before the next release.

I’ll also add a spec that expects Twitter::Errors.errors[403] to return Twitter::Error::Forbidden, since this is currently an unspecified expectation.

@pengwynn
Copy link
Collaborator Author

👍

I've since run into that in Octokit, too (with GitHub's 403 responses). I'm looking at the best way to handle that, perhaps with a .match? on each error type method that evaluates status and response body, picking the deepest child that returns true for that method.

@sferik sferik closed this in 7284394 Aug 18, 2013
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

Successfully merging this pull request may close these issues.

None yet

3 participants