Skip to content

Commit

Permalink
fix: handle non-json errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ruscoder committed Nov 22, 2024
1 parent 6db93b5 commit 924f877
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion fhirsnake/watch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 924f877

Please sign in to comment.