added error handling for all requests

This commit is contained in:
p.loedige 2020-12-28 12:30:00 +01:00
parent 37cb64a2ab
commit 9c56c1b2d2

13
app.py
View File

@ -23,16 +23,13 @@ def api_root():
@app.route('/device/<device_name>/', methods=["GET", "POST"]) @app.route('/device/<device_name>/', methods=["GET", "POST"])
def api_leds_control(device_name): def api_leds_control(device_name):
if request.method == "POST": try:
# if color in LEDS: if request.method == "POST":
# GPIO.output(LEDS[color], int(request.data.get("state")))
try:
response = interface_handler.write(device_name,request.data.get("output")) response = interface_handler.write(device_name,request.data.get("output"))
return {'output': response} return {'output': response}
except Exception as e: return {'state': interface_handler.read(device_name)}
return {'error': str(e)} except Exception as e:
# return {color: GPIO.input(LEDS[color])} return {'error': str(e)}
return {'state': interface_handler.read(device_name)}
if __name__ == "__main__": if __name__ == "__main__":
app.run(port=8080,host="0.0.0.0") app.run(port=8080,host="0.0.0.0")