Handling errors cases
This commit is contained in:
parent
7b234fc708
commit
d75122ad5c
1 changed files with 9 additions and 7 deletions
16
myapp.py
16
myapp.py
|
@ -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__":
|
||||
|
|
Loading…
Reference in a new issue