Skip to content
This repository has been archived by the owner on Aug 14, 2024. It is now read-only.

Commit

Permalink
raise an InvalidRequestError for a 422 http response
Browse files Browse the repository at this point in the history
  • Loading branch information
Jannik Graw committed Jan 15, 2016
1 parent d5f01c4 commit 2436b75
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/shipcloud/shipcloud_error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def self.from_response(response)

def self.error_class_for(response_code)
case response_code
when 400 then InvalidRequestError
when 400, 422 then InvalidRequestError
when 401 then AuthenticationError
when 402 then TooManyRequests
when 404 then NotFoundError
Expand Down
8 changes: 8 additions & 0 deletions spec/shipcloud/shipcloud_error_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
end
end

context "with a response with status code 422" do
it "returns a Shipcloud::InvalidRequestError" do
expect(Shipcloud::ShipcloudError.from_response(build_response(status_code: 422))).to be_a(
Shipcloud::InvalidRequestError
)
end
end

context "with a response with status code 401" do
it "returns a Shipcloud::AuthenticationError" do
expect(Shipcloud::ShipcloudError.from_response(build_response(status_code: 401))).to be_a(
Expand Down

0 comments on commit 2436b75

Please sign in to comment.