From 178d724ec01b1ad3395b96714778e75d6880d115 Mon Sep 17 00:00:00 2001 From: Natalia Serrano Date: Fri, 13 Sep 2024 12:35:15 +0200 Subject: [PATCH] refs #702 have RESTApi.py handle errors and non-json responses --- src/opengnsys/RESTApi.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/opengnsys/RESTApi.py b/src/opengnsys/RESTApi.py index 8773cf5..3e3468f 100644 --- a/src/opengnsys/RESTApi.py +++ b/src/opengnsys/RESTApi.py @@ -142,6 +142,10 @@ class REST(object): else: r = requests.post(url, data=data, headers={'content-type': 'application/json'}) + r.raise_for_status() + ct = r.headers['Content-Type'] + if 'application/json' != ct: + raise Exception (f'response content-type is not "application/json" but "{ct}"') r = json.loads(r.content) # Using instead of r.json() to make compatible with old requests lib versions except requests.exceptions.RequestException as e: raise ConnectionError(e)