Skip to content

Raise a dedicated error class with 429 responses#154

Merged
dblock merged 2 commits intoslack-ruby:masterfrom
greggroth:429-errors
Jul 27, 2017
Merged

Raise a dedicated error class with 429 responses#154
dblock merged 2 commits intoslack-ruby:masterfrom
greggroth:429-errors

Conversation

@greggroth
Copy link
Copy Markdown
Contributor

Ensure the error message includes the value of the "Retry-After" header
so the client knows when it's safe to retry requests.

Closes #153

it 'fails with an specific exception' do
begin
client.auth_test
rescue Slack::Web::Api::TooManyRequestsError => e
Copy link
Copy Markdown
Contributor Author

@greggroth greggroth Jul 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this new error class does not inherit from Faraday::ClientError, so if a client is expecting to rescue that error in the case of a 429 response code, this PR will break that behavior.

@greggroth greggroth force-pushed the 429-errors branch 2 times, most recently from b07a326 to dd0e69e Compare July 25, 2017 22:09
Ensure the error message includes the value of the "Retry-After" header
so the client knows when it's safe to retry requests.
Comment thread lib/slack-ruby-client.rb Outdated
end
require_relative 'slack/web/config'
require_relative 'slack/web/api/error'
require_relative 'slack/web/api/too_many_requests_error'
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets move it to an errors folder?

module Slack
module Web
module Api
class TooManyRequestsError < ::Faraday::Error
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

module Errors

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be confusing that this error is namespaced under Slack::Web::Api::Errors while the existing Slack::Web::Api::Error class is not namespaced (and is very close to Slack::Web::Api::Errors). Do you still want the change?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so. It's not uncommon. We can also do a Slack::Web::Api::Errors::Base and alias the old one for backward compatibility if you want to, your call.

@dblock
Copy link
Copy Markdown
Collaborator

dblock commented Jul 26, 2017

This is great, just move it into a folder structure for future errors and I'll merge.

I moved `Slack::Web::Api::Error` to
`Slack::Web::Api::Errors::SlackError` but left the orginal constant
aliased to the new one.
@dblock
Copy link
Copy Markdown
Collaborator

dblock commented Jul 27, 2017

Looks great, merging.

@dblock dblock merged commit 727b49e into slack-ruby:master Jul 27, 2017
@greggroth greggroth deleted the 429-errors branch July 27, 2017 23:15
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.

2 participants