-
-
Notifications
You must be signed in to change notification settings - Fork 217
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
Handle server errors such as timouts & non-json responses #350
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't add this stuff into on_complete
like it's done in #307 because on_complete
is not called in that cases, we just raising from inner middleware.
let(:body) { {} } | ||
let(:env) { double status: status, response: response, body: body } | ||
|
||
describe '#call' do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that specs from here should be moved to Slack::Web::Client
and use vcr/be more integration-like than unit-like, please advise.
But right now we're not testing what really happens when server responds with 500/timeout/non-json.
|
||
def call(env) | ||
super | ||
rescue Slack::Web::Api::Errors::SlackError, Slack::Web::Api::Errors::TooManyRequestsError => e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think TooManyRequestsError
is an SlackError
so both here would get rescued with just SlackError
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
> Slack::Web::Api::Errors::TooManyRequestsError < Slack::Web::Api::Errors::SlackError
=> nil
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes because we inherited this one from Faraday::Error
to get retry_after
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe there needs to be an intermediate Slack::Web::Api::Errors::HttpRequestError
that holds an inner FaradayError
exception?
52897c7
to
fd1a398
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a clean green build please, README and UPGRADING updates. Otherwise LGTM.
rescue Slack::Web::Api::Errors::SlackError, Slack::Web::Api::Errors::TooManyRequestsError | ||
raise | ||
rescue ::Faraday::ParsingError | ||
raise Slack::Web::Api::Errors::ParsingError.new('parsing_error', env.response) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would sink parsing_error
message into the error definition itself when calling super
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what do you mean here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like this. I don't think there's some kind of convention that the first argument must be a string, but I could be wrong? This is not a must have change for me here.
raise Slack::Web::Api::Errors::ParsingError.new(env.response)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a user of this gem I'm expecting first argument (i. e. message) of Slack::Web::Api::Errors::Error
to be a kinda meaningful String
, while the second is response, that's how it works everywhere currently. So I assume that there actually is an implicit convention.
And while it will be more appropriate to catch & process Slack::Web::Api::Errors::ParsingError
separately — I assume something like
rescue Slack::Web::Api::Errors::Error => e
raise unless e.message == 'parsing_error'
also is expected to work.
But I also don't have strong feelings about this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My issue is that it's an argument to the constructor that hides the message argument. I was thinking like so:
class TimeoutError < HttpRequestError
def initialize(response)
super 'timeout_error'
end
end
raise Slack::Web::Api::Errors::TimeoutError
db96484
to
310a287
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my comments, expand on UPGRADING, add a CHANGELOG entry and this is good to go. Thanks for hanging in here!
rescue Slack::Web::Api::Errors::SlackError, Slack::Web::Api::Errors::TooManyRequestsError | ||
raise | ||
rescue ::Faraday::ParsingError | ||
raise Slack::Web::Api::Errors::ParsingError.new('parsing_error', env.response) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like this. I don't think there's some kind of convention that the first argument must be a string, but I could be wrong? This is not a must have change for me here.
raise Slack::Web::Api::Errors::ParsingError.new(env.response)
Needs a CHANGELOG entry otherwise good to go with or without the message/super change. |
637c8d1
to
2d9a489
Compare
CHANGELOG is added. |
Merged |
My stab @ #306
It's really a draft, but I want some feedback since I'm not really used to slack-ruby-client, so making it non-draft.