1
0
Fork 0
Browse Source

add try-blocks to post requests.

stable
Craig Oates 4 years ago
parent
commit
b01178a711
  1. 2
      app/app.py
  2. 6
      app/services/post_services.py

2
app/app.py

@ -21,4 +21,4 @@ def robots():
return render_template("robots.txt")
if __name__ == "__main__":
app.run(host="0.0.0.0", debug=True)
app.run(host="0.0.0.0", debug=False)

6
app/services/post_services.py

@ -19,6 +19,7 @@ the same directory as this: /services/.
device_check_token = "QWERTYuiopasdfghjklzxcvbnm_1234567890"
def add_latest_reading(meter, info):
try:
if info["token"] == device_check_token:
reading = {"reading":info["reading"], "time":info["time"]}
if meter == 1:
@ -29,8 +30,11 @@ def add_latest_reading(meter, info):
return add_reading_to_meter3(reading)
return make_response("Meter Id. not recognised. Must be between 1 and 3.", 400)
return make_response("Invalid token.", 400)
except:
return make_response("The data you sent was invalid or incorrectly formatted.", 400)
def log_status_change(device, info):
try:
if info["token"] == device_check_token:
status = {"time":info["time"], "status":info["status"]}
if device == 1:
@ -47,6 +51,8 @@ def log_status_change(device, info):
return add_status_change_to_device6(status)
return make_response("Device Id. not recognised. Must be between 1 and 6.", 400)
return make_response("Invalid token.", 400)
except:
return make_response("The data you sent was invalid or incorrectly formatted.", 400)
'''
Nitty-Gritty Functions