Skip to content

Commit

Permalink
include headers in Strava::Errors::Fault response (dblock#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesChevalier authored and dblock committed Nov 8, 2019
1 parent 50b50c3 commit f072fa8
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Automatically convert `before` and `after` arguments of `Strava::Api::Client#athlete_activities` from `Time` to `Integer` - [@dblock](https://github.com/dblock).
* [#18](https://github.com/dblock/strava-ruby-client/pull/18): Testing against Ruby 2.5.3 and 2.6.0 - [@lucianosousa](https://github.com/lucianosousa).
* [#18](https://github.com/dblock/strava-ruby-client/pull/18): Upgraded Rubocop to 0.61.1 - [@lucianosousa](https://github.com/lucianosousa).
* [#21](https://github.com/dblock/strava-ruby-client/pull/21): Include headers in error response - [@jameschevalier](https://github.com/jameschevalier).
* Your contribution here.

### 0.3.1 (2018/12/05)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,7 @@ begin
rescue Strava::Errors::Fault => e
e.message # => Bad Request
e.errors # => [{ 'code' => 'invalid', 'field' => 'code', 'resource' => 'RequestToken' }]
e.headers # => { "status" => "403 Bad Request", "x-ratelimit-limit" => "600,30000", "x-ratelimit-usage" => "314,27536" }
end
```

Expand Down
4 changes: 4 additions & 0 deletions lib/strava/errors/fault.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ def message
response[:body]['message'] || super
end

def headers
response[:headers]
end

def errors
response[:body]['errors']
end
Expand Down
26 changes: 26 additions & 0 deletions spec/strava/oauth/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,38 @@
it 'errors with an invalid client id', vcr: { cassette_name: 'oauth/token_invalid_client' } do
expect { client.oauth_token(code: 'code') }.to raise_error Strava::Errors::Fault do |e|
expect(e.message).to eq 'Bad Request'
expect(e.headers).to eq(
'cache-control' => 'no-cache',
'connection' => 'keep-alive',
'content-type' => 'application/json; charset=UTF-8',
'date' => 'Thu, 22 Nov 2018 20:16:41 GMT',
'status' => '400 Bad Request',
'transfer-encoding' => 'chunked',
'via' => '1.1 linkerd',
'x-content-type-options' => 'nosniff',
'x-frame-options' => 'SAMEORIGIN,DENY',
'x-request-id' => '168ffeae-9029-4aec-bd50-3a0430e594bd',
'x-xss-protection' => '1; mode=block'
)
expect(e.errors).to eq([{ 'code' => 'invalid', 'field' => 'client_id', 'resource' => 'Application' }])
end
end
it 'errors with an invalid code', vcr: { cassette_name: 'oauth/token_invalid_code' } do
expect { client.oauth_token(code: 'code') }.to raise_error Faraday::ClientError do |e|
expect(e.message).to eq 'Bad Request'
expect(e.headers).to eq(
'cache-control' => 'no-cache',
'connection' => 'keep-alive',
'content-type' => 'application/json; charset=UTF-8',
'date' => 'Thu, 22 Nov 2018 20:26:56 GMT',
'status' => '400 Bad Request',
'transfer-encoding' => 'chunked',
'via' => '1.1 linkerd',
'x-content-type-options' => 'nosniff',
'x-frame-options' => 'SAMEORIGIN,DENY',
'x-request-id' => 'd3406a4e-9099-400f-b709-aad0ea2768fe',
'x-xss-protection' => '1; mode=block'
)
expect(e.errors).to eq([{ 'code' => 'invalid', 'field' => 'code', 'resource' => 'RequestToken' }])
end
end
Expand Down

0 comments on commit f072fa8

Please sign in to comment.