chg: [backend] Print connection errors on terminal

This commit is contained in:
Sami Mokaddem 2024-07-01 14:48:00 +02:00
parent 3a575b0f7f
commit 0ee3f7ac13

View file

@ -21,7 +21,8 @@ def get(url, data={}, api_key=misp_apikey):
full_url = urljoin(misp_url, url) full_url = urljoin(misp_url, url)
try: try:
response = requests.get(full_url, data=data, headers=headers, verify=not misp_skipssl) response = requests.get(full_url, data=data, headers=headers, verify=not misp_skipssl)
except requests.exceptions.ConnectionError: except requests.exceptions.ConnectionError as e:
print(e)
return None return None
return response.json() if response.headers['content-type'].startswith('application/json') else response.text return response.json() if response.headers['content-type'].startswith('application/json') else response.text
@ -36,7 +37,8 @@ def post(url, data={}, api_key=misp_apikey):
full_url = urljoin(misp_url, url) full_url = urljoin(misp_url, url)
try: try:
response = requests.post(full_url, data=json.dumps(data), headers=headers, verify=not misp_skipssl) response = requests.post(full_url, data=json.dumps(data), headers=headers, verify=not misp_skipssl)
except requests.exceptions.ConnectionError: except requests.exceptions.ConnectionError as e:
print(e)
return None return None
return response.json() if response.headers['content-type'].startswith('application/json') else response.text return response.json() if response.headers['content-type'].startswith('application/json') else response.text