From d99f855d81802e0170780784286b2b5fcc31b2eb Mon Sep 17 00:00:00 2001 From: Maxime Jublou Date: Tue, 20 Feb 2024 20:59:15 +0100 Subject: [PATCH] fix: On a 500 status code do not try to read json --- .../utils/domains_base/secondary/BaseAPIAdaptor.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/naas_python/utils/domains_base/secondary/BaseAPIAdaptor.py b/naas_python/utils/domains_base/secondary/BaseAPIAdaptor.py index 4ed4816..fe1d326 100644 --- a/naas_python/utils/domains_base/secondary/BaseAPIAdaptor.py +++ b/naas_python/utils/domains_base/secondary/BaseAPIAdaptor.py @@ -89,8 +89,8 @@ def make_api_request( return api_response except requests.exceptions.HTTPError as e: - _response = api_response.json() if api_response.status_code == 401: + _response = api_response.json() _message = "" if "error_message" in _response: _message = _response["error_message"] @@ -103,13 +103,7 @@ def make_api_request( e, ) elif api_response.status_code == 500: - _message = "" - if "error_message" in _response: - _message = _response["error_message"] - elif "detail" in _response: - _message = _response["detail"] - else: - _message = "Internal Server Error" + _message = "Internal Server Error" raise ServiceStatusError(_message, e) else: # Other status codes will be handled by the calling method