From 76e25aa8e6b41b5c0375fe2ba1bd9cdc064c9859 Mon Sep 17 00:00:00 2001 From: Bhavya Y Date: Tue, 16 Apr 2024 21:00:13 +0530 Subject: [PATCH 1/2] Handling error exception gracefully for OAuth API failures --- lib/razorpay/request.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/razorpay/request.rb b/lib/razorpay/request.rb index e33ed8d..66b5234 100644 --- a/lib/razorpay/request.rb +++ b/lib/razorpay/request.rb @@ -129,6 +129,9 @@ def raise_error(error, status) klass = Razorpay.const_get(class_name) raise klass.new(*args), error['description'] rescue NameError, LoadError + if error.key?('description') + raise Razorpay::Error.new, error['description'] + end # We got an unknown error, cast it to Error for now raise Razorpay::Error.new, 'Unknown Error' end From df9c816dedee6ff1cfb18f65454208cdef3944b7 Mon Sep 17 00:00:00 2001 From: Bhavya Y Date: Tue, 16 Apr 2024 22:41:33 +0530 Subject: [PATCH 2/2] Fixing test case --- lib/razorpay/request.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/razorpay/request.rb b/lib/razorpay/request.rb index 66b5234..df82654 100644 --- a/lib/razorpay/request.rb +++ b/lib/razorpay/request.rb @@ -129,7 +129,7 @@ def raise_error(error, status) klass = Razorpay.const_get(class_name) raise klass.new(*args), error['description'] rescue NameError, LoadError - if error.key?('description') + if !error.nil? && error.key?('description') raise Razorpay::Error.new, error['description'] end # We got an unknown error, cast it to Error for now