Skip to content

Commit 7db34a8

Browse files
authored
Merge pull request #401 from wilsondealmeida/net-http-402-payment-required
HTTP status 402 PaymentRequired
2 parents 623ebaf + 9ffe007 commit 7db34a8

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
@@ -212,6 +212,7 @@ module ActiveResource
212212
# * 301, 302, 303, 307 - ActiveResource::Redirection
213213
# * 400 - ActiveResource::BadRequest
214214
# * 401 - ActiveResource::UnauthorizedAccess
215+
# * 402 - ActiveResource::PaymentRequired
215216
# * 403 - ActiveResource::ForbiddenAccess
216217
# * 404 - ActiveResource::ResourceNotFound
217218
# * 405 - ActiveResource::MethodNotAllowed

lib/active_resource/connection.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ def handle_response(response)
139139
raise(BadRequest.new(response))
140140
when 401
141141
raise(UnauthorizedAccess.new(response))
142+
when 402
143+
raise(PaymentRequired.new(response))
142144
when 403
143145
raise(ForbiddenAccess.new(response))
144146
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)