Skip to content

Commit

Permalink
Added Slack::Web::Api::Error#response, closes slack-ruby#22.
Browse files Browse the repository at this point in the history
  • Loading branch information
dblock committed Nov 30, 2015
1 parent 9d9bfe0 commit 636f6c1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* [#34](https://github.com/dblock/slack-ruby-client/pull/34): Added `Slack::RealTime::Client#start_async` - [@mikz](https://github.com/mikz), [@dblock](https://github.com/dblock).
* `Slack::RealTime::Client` supports `:open` and `:close` callbacks - [@dblock](https://github.com/dblock).
* [#32](https://github.com/dblock/slack-ruby-client/issues/32): Fix: `on_complete: undefined method [] for nil:NilClass` when responding to Slack 400-500 errors - [@dblock](https://github.com/dblock).
* [#22](https://github.com/dblock/slack-ruby-client/issues/22): Added `Slack::Web::Api::Error#response` - [@dblock](https://github.com/dblock).
* Your contribution here.

### 0.4.0 (11/8/2015)
Expand Down
6 changes: 6 additions & 0 deletions lib/slack/web/api/error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ module Slack
module Web
module Api
class Error < ::Faraday::Error
attr_reader :response

def initialize(message, response)
@response = response
super message
end
end
end
end
Expand Down
3 changes: 2 additions & 1 deletion lib/slack/web/faraday/response/raise_error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ module Response
class RaiseError < ::Faraday::Response::Middleware
def on_complete(env)
body = env.body
fail Slack::Web::Api::Error, body['error'] unless body['ok']
return if body['ok']
fail Slack::Web::Api::Error.new(body['error'], env.response)
end
end
end
Expand Down
14 changes: 14 additions & 0 deletions spec/slack/web/api/error_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require 'spec_helper'

RSpec.describe Slack::Web::Api::Error do
let(:client) { Slack::Web::Client.new }
it 'provides access to the response object', vcr: { cassette_name: 'web/auth_test_error' } do
begin
client.auth_test
fail 'Expected to receive Slack::Web::Api::Error.'
rescue Slack::Web::Api::Error => e
expect(e.response).to_not be_nil
expect(e.response.status).to eq 200
end
end
end

0 comments on commit 636f6c1

Please sign in to comment.