diff --git a/commerce_coordinator/apps/paypal/views.py b/commerce_coordinator/apps/paypal/views.py index 03cea41c..94e5f984 100644 --- a/commerce_coordinator/apps/paypal/views.py +++ b/commerce_coordinator/apps/paypal/views.py @@ -41,12 +41,12 @@ def _get_certificate(self, url): """ Get certificate from the given URL """ + if not self._is_valid_url(url): + raise ValueError("Invalid or untrusted URL provided") try: - if not self._is_valid_url(url): - raise ValueError("Invalid or untrusted URL provided") from e cache = KeyValueCache.objects.get(cache_key=url) return cache.value - except Exception as e: # pylint: disable=broad-exception-caught + except KeyValueCache.DoesNotExist: r = requests.get(url) # pylint: disable=missing-timeout KeyValueCache.objects.create(cache_key=url, cache_value=r.text) return r.text