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

Handle server errors such as timouts & non-json responses #350

Merged
merged 1 commit into from
Nov 1, 2020

Conversation

ojab
Copy link
Contributor

@ojab ojab commented Oct 12, 2020

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.

Copy link
Contributor Author

@ojab ojab left a 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.

lib/slack/web/faraday/response/raise_error.rb Outdated Show resolved Hide resolved
lib/slack/web/faraday/response/raise_error.rb Outdated Show resolved Hide resolved
let(:body) { {} }
let(:env) { double status: status, response: response, body: body }

describe '#call' do
Copy link
Contributor Author

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
Copy link
Collaborator

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

Copy link
Contributor Author

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

Copy link
Collaborator

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.

Copy link
Collaborator

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?

lib/slack/web/faraday/response/raise_error.rb Outdated Show resolved Hide resolved
@ojab ojab force-pushed the master branch 4 times, most recently from 52897c7 to fd1a398 Compare October 17, 2020 16:26
@ojab ojab requested a review from dblock October 20, 2020 09:34
Copy link
Collaborator

@dblock dblock left a 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.

lib/slack/web/faraday/response/raise_error.rb Outdated Show resolved Hide resolved
spec/slack/web/api/errors/service_unavailable_spec.rb Outdated Show resolved Hide resolved
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)
Copy link
Collaborator

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

Copy link
Contributor Author

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.

Copy link
Collaborator

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)

Copy link
Contributor Author

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.

Copy link
Collaborator

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

@ojab ojab force-pushed the master branch 6 times, most recently from db96484 to 310a287 Compare October 26, 2020 15:57
Copy link
Collaborator

@dblock dblock left a 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!

.rubocop.yml Outdated Show resolved Hide resolved
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)
Copy link
Collaborator

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)

UPGRADING.md Show resolved Hide resolved
@dblock
Copy link
Collaborator

dblock commented Oct 30, 2020

Needs a CHANGELOG entry otherwise good to go with or without the message/super change.

@ojab ojab force-pushed the master branch 2 times, most recently from 637c8d1 to 2d9a489 Compare November 1, 2020 12:55
@ojab
Copy link
Contributor Author

ojab commented Nov 1, 2020

CHANGELOG is added.

@dblock dblock merged commit c320e8f into slack-ruby:master Nov 1, 2020
@dblock
Copy link
Collaborator

dblock commented Nov 1, 2020

Merged

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