Skip to content

Commit 9ffe007

Browse files
HTTP status 402 PaymentRequired
1 parent e6162f5 commit 9ffe007

File tree

4 files changed

+10
-0
lines changed

4 files changed

+10
-0
lines changed

lib/active_resource/base.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ module ActiveResource
213213
# * 301, 302, 303, 307 - ActiveResource::Redirection
214214
# * 400 - ActiveResource::BadRequest
215215
# * 401 - ActiveResource::UnauthorizedAccess
216+
# * 402 - ActiveResource::PaymentRequired
216217
# * 403 - ActiveResource::ForbiddenAccess
217218
# * 404 - ActiveResource::ResourceNotFound
218219
# * 405 - ActiveResource::MethodNotAllowed

lib/active_resource/connection.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ def handle_response(response)
140140
raise(BadRequest.new(response))
141141
when 401
142142
raise(UnauthorizedAccess.new(response))
143+
when 402
144+
raise(PaymentRequired.new(response))
143145
when 403
144146
raise(ForbiddenAccess.new(response))
145147
when 404

lib/active_resource/exceptions.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ class BadRequest < ClientError # :nodoc:
5757
class UnauthorizedAccess < ClientError # :nodoc:
5858
end
5959

60+
# 402 Payment Required
61+
class PaymentRequired < ClientError # :nodoc:
62+
end
63+
6064
# 403 Forbidden
6165
class ForbiddenAccess < ClientError # :nodoc:
6266
end

test/cases/connection_test.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ def test_handle_response
7474
# 401 is an unauthorized request
7575
assert_response_raises ActiveResource::UnauthorizedAccess, 401
7676

77+
# 402 is a payment required error.
78+
assert_response_raises ActiveResource::PaymentRequired, 402
79+
7780
# 403 is a forbidden request (and authorizing will not help)
7881
assert_response_raises ActiveResource::ForbiddenAccess, 403
7982

0 commit comments

Comments
 (0)