Handling errors cases

This commit is contained in:
chabisik 2022-12-22 09:06:28 +01:00
parent 7b234fc708
commit d75122ad5c

View file

@ -12,8 +12,9 @@ app = flask.Flask(import_name=__name__, template_folder=".")
try:
sys.path.insert(0,'/home/pi/information')
import config
except:
print("Unable to add 'information' folder into system path")
print("Unable to add 'information' folder into system path OR 'config.py' not found")
lock = threading.Lock()
def opener(lck):
@ -83,32 +84,33 @@ def receiver():
print(data_dict)
response_events = {"events":[]}
#---action=incoming---
if data_dict["action"]=="incoming":
if "action" in data_dict and data_dict["action"]=="incoming":
if "please" in data_dict["message"].lower():
op = threading.Thread(target=opener, args=(lock,))
op.start()
response_events["events"].append({"event":"log","message":"Server received "+data_dict["message_type"]+" from "+data_dict["from"]})
return flask.jsonify(response_events)
#---action=outgoing---
if data_dict["action"]=="outgoing":
if "action" in data_dict and data_dict["action"]=="outgoing":
response_events["events"].append({"event":"log","message":"Server received outgoing action"})
return flask.jsonify(response_events)
#---action=send_status---
if data_dict["action"]=="send_status":
if "action" in data_dict and data_dict["action"]=="send_status":
response_events["events"].append({"event":"log","message":"Server received send_status action"})
return flask.jsonify(response_events)
#---action=forward_sent---
if data_dict["action"]=="forward_sent":
if "action" in data_dict and data_dict["action"]=="forward_sent":
response_events["events"].append({"event":"log","message":"Server received forward_sent action"})
return flask.jsonify(response_events)
#---action=amqp_started---
if data_dict["action"]=="amqp_started":
if "action" in data_dict and data_dict["action"]=="amqp_started":
response_events["events"].append({"event":"log","message":"Server received amqp_started action"})
return flask.jsonify(response_events)
#---action=device_status---
if data_dict["action"]=="device_status":
if "action" in data_dict and data_dict["action"]=="device_status":
response_events["events"].append({"event":"log","message":"Server received notification of "+data_dict["status"]})
return flask.jsonify(response_events)
return flask.abort(400)
if __name__=="__main__":