From 924f87773251434a589129753decd71c6386d072 Mon Sep 17 00:00:00 2001 From: Vadim Laletin Date: Fri, 22 Nov 2024 15:58:15 +0100 Subject: [PATCH] fix: handle non-json errors --- fhirsnake/watch.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/fhirsnake/watch.py b/fhirsnake/watch.py index d04a2f1..e469b49 100644 --- a/fhirsnake/watch.py +++ b/fhirsnake/watch.py @@ -52,13 +52,20 @@ def process_file(self, file_path): response = requests.put( url, json=resource, headers={"Content-Type": "application/json", **self.external_fhir_server_headers} ) + + formatted_error = response.text + try: + formatted_error = json.dumps(json.loads(formatted_error), indent=2) + except json.JSONDecodeError: + pass + if response.status_code >= 400: logging.error( "Unable to update %s via %s (%s):\a\n %s", file_path, url, response.status_code, - json.dumps(response.json(), indent=2), + formatted_error, ) else: logging.info("Updated %s via %s (%s)", file_path, url, response.status_code)