Skip to content

Commit

Permalink
HTTP status 402 PaymentRequired
Browse files Browse the repository at this point in the history
  • Loading branch information
wilsondealmeida committed Jan 25, 2024
1 parent e6162f5 commit 9ffe007
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/active_resource/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ module ActiveResource
# * 301, 302, 303, 307 - ActiveResource::Redirection
# * 400 - ActiveResource::BadRequest
# * 401 - ActiveResource::UnauthorizedAccess
# * 402 - ActiveResource::PaymentRequired
# * 403 - ActiveResource::ForbiddenAccess
# * 404 - ActiveResource::ResourceNotFound
# * 405 - ActiveResource::MethodNotAllowed
Expand Down
2 changes: 2 additions & 0 deletions lib/active_resource/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ def handle_response(response)
raise(BadRequest.new(response))
when 401
raise(UnauthorizedAccess.new(response))
when 402
raise(PaymentRequired.new(response))
when 403
raise(ForbiddenAccess.new(response))
when 404
Expand Down
4 changes: 4 additions & 0 deletions lib/active_resource/exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ class BadRequest < ClientError # :nodoc:
class UnauthorizedAccess < ClientError # :nodoc:
end

# 402 Payment Required
class PaymentRequired < ClientError # :nodoc:
end

# 403 Forbidden
class ForbiddenAccess < ClientError # :nodoc:
end
Expand Down
3 changes: 3 additions & 0 deletions test/cases/connection_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ def test_handle_response
# 401 is an unauthorized request
assert_response_raises ActiveResource::UnauthorizedAccess, 401

# 402 is a payment required error.
assert_response_raises ActiveResource::PaymentRequired, 402

# 403 is a forbidden request (and authorizing will not help)
assert_response_raises ActiveResource::ForbiddenAccess, 403

Expand Down

0 comments on commit 9ffe007

Please sign in to comment.