Skip to content
Snippets Groups Projects
Commit 95d6e368 authored by Tim Jaacks's avatar Tim Jaacks
Browse files

alphaplan_fwr_import: add error handling

parent 277d4af7
No related branches found
No related tags found
1 merge request!227CI-test: new deploy pipeline
Pipeline #46338 passed with stages
in 1 minute and 10 seconds
......@@ -9,12 +9,21 @@ import requests
def ap_send_json(jsonobj: dict, url: str, user: str, password: str, cert_file: str):
"""Sends the generated files to the Alphaplan webservice"""
msg = requests.post(
url, json=jsonobj, auth=(user, password), verify=cert_file, timeout=10
)
msg_json = msg.json()
try:
msg = requests.post(
url, json=jsonobj, auth=(user, password), verify=cert_file, timeout=10
)
except requests.exceptions.RequestException as e:
sys.exit("ERROR: %s" % e)
try:
msg_json = msg.json()
except json.decoder.JSONDecodeError:
sys.exit("ERROR: Did not receive a valid JSON reply from Alphaplan webservice")
if msg_json["Status"] != "Ok":
sys.exit("ERROR: AlphaPlan webservice post request failed")
print("AlphaPlan webservice response: {}".format(msg_json["Meldung"]))
......@@ -62,8 +71,13 @@ def main():
for filename in files:
print("Importing JSON file %s" % filename)
with open(filename, "r", encoding="utf-8") as f:
try:
json_data = json.load(f)
except json.decoder.JSONDecodeError:
sys.exit("ERROR: Could not parse JSON data from %f" % filename)
ap_send_json(
json.load(f),
json_data,
args.url,
args.user,
args.password,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment