Skip to content

Commit

Permalink
Merge pull request Shopify#54 from Shopify/ltk/revert-3b02b3227
Browse files Browse the repository at this point in the history
Revert raise-on-non-2xx response behavior
  • Loading branch information
ltk authored Jan 20, 2022
2 parents d85e912 + ebe892f commit 1c58db5
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 23 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## [v0.3.1] - 2022-01-20
- [Reverts a breaking change that caused errors to be raised for non-2xx responses](https://github.com/Shopify/oktakit/pull/54)

## [v0.3.0] - 2022-01-20
- [Adds support for Ruby 3](https://github.com/Shopify/oktakit/pull/42)
- [Adds support for user reactivation endpoint](https://github.com/Shopify/oktakit/pull/47)
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
oktakit (0.3.0)
oktakit (0.3.1)
sawyer (~> 0.8.1)

GEM
Expand Down
2 changes: 2 additions & 0 deletions lib/oktakit/response/raise_error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ module Response
# This class raises an Oktakit-flavored exception based
# HTTP status codes returned by the API
class RaiseError < Faraday::Response::Middleware
private

def on_complete(response)
if (error = Oktakit::Error.from_response(response))
raise error
Expand Down
2 changes: 1 addition & 1 deletion lib/oktakit/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Oktakit
VERSION = '0.3.0'.freeze
VERSION = '0.3.1'.freeze
end
43 changes: 22 additions & 21 deletions spec/oktakit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,30 @@
end
end

ERRORS = {
400 => Oktakit::BadRequest,
401 => Oktakit::Unauthorized,
403 => Oktakit::Forbidden,
404 => Oktakit::NotFound,
405 => Oktakit::MethodNotAllowed,
406 => Oktakit::NotAcceptable,
409 => Oktakit::Conflict,
415 => Oktakit::UnsupportedMediaType,
422 => Oktakit::UnprocessableEntity,
418 => Oktakit::ClientError,
500 => Oktakit::InternalServerError,
501 => Oktakit::NotImplemented,
502 => Oktakit::BadGateway,
503 => Oktakit::ServiceUnavailable,
504 => Oktakit::ServerError,
}
ERROR_STATUSES = [
400,
401,
403,
404,
405,
406,
409,
415,
422,
418,
500,
501,
502,
503,
504,
]

describe 'errors' do
ERRORS.each do |code, error|
it "raises a #{error} on #{code} responses" do
VCR.use_cassette(code) do
expect { client.get('/users/-1') }.to(raise_error(error))
ERROR_STATUSES.each do |error_status|
it "returns a #{error_status} status for #{error_status} responses" do
VCR.use_cassette(error_status) do
_, response_status = client.get('/users/-1')
expect(response_status).to eq(error_status)
end
end
end
Expand Down

0 comments on commit 1c58db5

Please sign in to comment.