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

Add response_metadata to Web API errors #311

Merged
merged 12 commits into from
Mar 10, 2020
Merged

Conversation

jmanian
Copy link
Collaborator

@jmanian jmanian commented Feb 19, 2020

Relates to #310

  1. SlackError#error and SlackError#response_metadata methods give direct access to these fields in Slack's response body.
  2. Improvements to README

Original description below, from the first draft of this PR that did a lot more:

There are two main things happening here:

  1. SlackError#error and SlackError#response_metadata methods give direct access to these fields in Slack's response body.
  2. A new verbose_errors option changes the message on SlackError to include response_metadata.

I hit one snag, which is that I wasn't sure how to access the client instance within Slack::Web::Faraday::Response::RaiseError, which is where the error message is currently assembled. This means that I could not read the verbose_errors setting off of the client itself, but instead had to pull it from the config, which means that it is not configurable at the client instance level.

@jmanian jmanian requested a review from dblock February 19, 2020 19:34
@@ -10,6 +10,18 @@ def initialize(message, response = nil)
super message
@response = response
end

def error
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is sort of a horrible name. I used it because it's the name of the field in the response body, but I'm open to changing it. One alternative is error_code (and error_codes below).

@@ -10,7 +10,7 @@ class Client

def initialize(options = {})
Slack::Web::Config::ATTRIBUTES.each do |key|
send("#{key}=", options[key] || Slack::Web.config.send(key))
send("#{key}=", options.fetch(key, Slack::Web.config.send(key)))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This turned out to not be directly relevant, but I noticed that if there was a truthy value in the config that it could not be overridden with a falsey value.

@dblock
Copy link
Collaborator

dblock commented Feb 24, 2020

To be honest, I dislike this. We are introducing a global flag to control formatting of an error message. It just feels wrong to me.

Can we split this PR into two parts and get the non-controversial parts merged? I like SlackError#error and SlackError#response_metadata methods that give direct access to these fields in Slack's response body and much of the doc changes. We can think of how to solve your other problem then (I have some ideas)?

@jmanian
Copy link
Collaborator Author

jmanian commented Feb 24, 2020

Sure, I see what you're saying. I'll pull out the global option and the corresponding change to the error message.

@jmanian
Copy link
Collaborator Author

jmanian commented Mar 10, 2020

@dblock updated

@jmanian jmanian changed the title Add verbose_errors option for web client Add response_metadata to Web API errors Mar 10, 2020
@@ -4,13 +4,22 @@
RSpec.describe Slack::Web::Api::Errors::SlackError do
let(:client) { Slack::Web::Client.new }

it 'provides access to the response object', vcr: { cassette_name: 'web/auth_test_error' } do
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 also leave that old test in-place and add checks for its .message, .error, .response_metadata, it's a simpler case, but will prevent breaking it in the future.

@dblock
Copy link
Collaborator

dblock commented Mar 10, 2020

LGTM, feel free to (re)add that missing test and squash-merge on 💚

@dblock
Copy link
Collaborator

dblock commented Mar 10, 2020

Needs rubocop -a ; rubocop --auto-gen-config

@jmanian
Copy link
Collaborator Author

jmanian commented Mar 10, 2020

Oh I just saw your comment. I resolved by following the rule.

@jmanian jmanian merged commit 067dc06 into slack-ruby:master Mar 10, 2020
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