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

Support for Net::HTTPPaymentRequired #392

Open
wilsondealmeida opened this issue Jun 5, 2023 · 2 comments
Open

Support for Net::HTTPPaymentRequired #392

wilsondealmeida opened this issue Jun 5, 2023 · 2 comments

Comments

@wilsondealmeida
Copy link

There's no ActiveResource exception for HTTP status 402.
It is already used by Shopify (https://shopify.dev/docs/api/usage/response-codes).

It can be an easy PR.

diff --git a/lib/active_resource/base.rb b/lib/active_resource/base.rb
index 766338b..f1189cb 100644
--- a/lib/active_resource/base.rb
+++ b/lib/active_resource/base.rb
@@ -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
diff --git a/lib/active_resource/connection.rb b/lib/active_resource/connection.rb
index e997a0a..b7168f0 100644
--- a/lib/active_resource/connection.rb
+++ b/lib/active_resource/connection.rb
@@ -140,6 +140,8 @@ module ActiveResource
           raise(BadRequest.new(response))
         when 401
           raise(UnauthorizedAccess.new(response))
+        when 402
+          raise(PaymentRequired.new(response))
         when 403
           raise(ForbiddenAccess.new(response))
         when 404
diff --git a/lib/active_resource/exceptions.rb b/lib/active_resource/exceptions.rb
index 08daeca..916ed8a 100644
--- a/lib/active_resource/exceptions.rb
+++ b/lib/active_resource/exceptions.rb
@@ -57,6 +57,10 @@ module ActiveResource
   class UnauthorizedAccess < ClientError # :nodoc:
   end
 
+  # 402 Payment Required
+  class PaymentRequired < ClientError # :nodoc:
+  end
+
   # 403 Forbidden
   class ForbiddenAccess < ClientError # :nodoc:
   end
diff --git a/test/cases/connection_test.rb b/test/cases/connection_test.rb
index c879f4c..3dba252 100644
--- a/test/cases/connection_test.rb
+++ b/test/cases/connection_test.rb
@@ -74,6 +74,9 @@ class ConnectionTest < ActiveSupport::TestCase
     # 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
@rafaelfranca
Copy link
Member

Can you please send the PR?

@wilsondealmeida
Copy link
Author

@rafaelfranca
#401

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants