From 4583ef58208e92018531f74557beb7dd33aff5ff Mon Sep 17 00:00:00 2001 From: Marco Antonio Gil Date: Wed, 24 Jun 2026 13:38:12 +0200 Subject: [PATCH] PTHMINT-128: Prevent attribute error by checking if response exists before accessing status_code in exception handler --- src/multisafepay/client/client.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/multisafepay/client/client.py b/src/multisafepay/client/client.py index 5854e30..a7330e4 100644 --- a/src/multisafepay/client/client.py +++ b/src/multisafepay/client/client.py @@ -344,6 +344,7 @@ def _create_request( "Content-Type": "application/json", } + response = None try: response = self.transport.request( method=method, @@ -354,7 +355,8 @@ def _create_request( response.raise_for_status() except Exception as e: if ( - hasattr(response, "status_code") + response is not None + and hasattr(response, "status_code") and 500 <= response.status_code < 600 ): raise ApiException(f"Request failed: {e}") from e