From c78c9330ea8e6b6768d6d123f316ba0f9da7f9bb Mon Sep 17 00:00:00 2001 From: Aungkokolin1997 Date: Tue, 5 Mar 2024 06:35:09 +0000 Subject: [PATCH] [IMP] payment_paypal: improve error handling in paypal validation This commit enhances the error handling for the PayPal validation request in the payment_paypal. Previously, failures in the urllib2.urlopen call during PayPal response validation were not caught, which could lead to unhandled exceptions if the network request failed. With this update, any exceptions raised during the validation request are now caught, and an appropriate error log is generated. --- addons/payment_paypal/controllers/main.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/addons/payment_paypal/controllers/main.py b/addons/payment_paypal/controllers/main.py index 00359c4d03874..23028c67ffc11 100644 --- a/addons/payment_paypal/controllers/main.py +++ b/addons/payment_paypal/controllers/main.py @@ -76,7 +76,11 @@ def paypal_validate_data(self, **post): new_post['cmd'] = '_notify-synch' # command is different in PDT than IPN/DPN validate_url = paypal_urls['paypal_form_url'] urequest = urllib2.Request(validate_url, werkzeug.url_encode(new_post)) - uopen = urllib2.urlopen(urequest) + try: + uopen = urllib2.urlopen(urequest) + except Exception as e: + _logger.exception('PayPal: validation request failed, with url %s, data %s, exception %s', validate_url, new_post, e) + return res resp = uopen.read() if pdt_request: resp, post = self._parse_pdt_response(resp)