Skip to content

Commit

Permalink
Merge pull request #31 from zendesk/mciupak/support_precondition_fail…
Browse files Browse the repository at this point in the history
…ed_error

Add ApiClient::Errors::PreconditionFailed
  • Loading branch information
marekciupak authored May 5, 2021
2 parents c441bf1 + befcb16 commit 58b1ab3
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.5.26

* Add support for HTTP status code: 412 Precondition Failed

# 0.5.25

* Fix broken gem build (gemspec files)
Expand Down
2 changes: 2 additions & 0 deletions lib/api_client/connection/basic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ def handle_response(request, response)
raise ApiClient::Errors::Conflict.new(nil, request, response)
when 410
raise ApiClient::Errors::Gone.new(nil, request, response)
when 412
raise ApiClient::Errors::PreconditionFailed.new(nil, request, response)
when 422
raise ApiClient::Errors::UnprocessableEntity.new(response.body, request, response)
when 423
Expand Down
1 change: 1 addition & 0 deletions lib/api_client/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Conflict < ApiClientError; end
class Gone < ApiClientError; end
class ServerError < ApiClientError; end
class UnprocessableEntity < ApiClientError; end
class PreconditionFailed < ApiClientError; end
class Locked < ApiClientError; end
class TooManyRequests < ApiClientError; end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/api_client/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module ApiClient
VERSION = '0.5.25'
VERSION = '0.5.26'
end
7 changes: 7 additions & 0 deletions spec/api_client/connection/basic_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,13 @@
}.should raise_error(ApiClient::Errors::Gone, "Status code: 410")
end

it "raises an ApiClient::Errors::PreconditionFailed if status is 412" do
@response.env[:status] = 412
lambda {
@instance.send :handle_response, request, @response
}.should raise_error(ApiClient::Errors::PreconditionFailed, "Status code: 412")
end

it "raises an ApiClient::Errors::Unsupported if status is 422" do
@response.env[:status] = 422
lambda {
Expand Down

0 comments on commit 58b1ab3

Please sign in to comment.