Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTP status 402 PaymentRequired #401

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/active_resource/base.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions lib/active_resource/connection.rb
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions lib/active_resource/exceptions.rb
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions test/cases/connection_test.rb
Original file line number Diff line number Diff line change
@@ -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