Skip to content

Commit

Permalink
feat: Include details for web api errors
Browse files Browse the repository at this point in the history
fixes: slack-ruby#482

Currently when we get the error message we get no details of what went
wrong unless we get the response_metadata for the error which is not
intuitive as most people when they get an error and print the exception
they would expect to see as much details as possible.

Additionally updated ruby-version in the project to be the latest as
most people would be using that one as their default, though not
changing the one required by the gem
  • Loading branch information
kevinrobayna committed Jun 23, 2023
1 parent bf5bb4b commit 382e357
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.7.6
3.2.0
6 changes: 6 additions & 0 deletions lib/slack/web/api/errors/slack_error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ def errors
def response_metadata
response.body.response_metadata
end

def to_s
errors_message = ", errors=#{errors}" unless errors.nil?
response_metadata_message = ", response_metadata=#{response_metadata}" unless response_metadata.nil?
"#{error}#{errors_message || ''}#{response_metadata_message || ''}"
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/slack/web/api/errors/slack_error_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
rescue described_class => e
expect(e.response).not_to be_nil
expect(e.response.status).to eq 200
expect(e.message).to eql 'invalid_arguments'
expect(e.message).to eql "invalid_arguments, response_metadata=#{e.response_metadata}"
expect(e.error).to eql 'invalid_arguments'
expect(e.response_metadata).to eq(
'messages' => [
Expand Down

0 comments on commit 382e357

Please sign in to comment.