From 9c56c1b2d2738f712c439872b92f5e80fbd1c0b4 Mon Sep 17 00:00:00 2001 From: "p.loedige" Date: Mon, 28 Dec 2020 12:30:00 +0100 Subject: [PATCH] added error handling for all requests --- app.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/app.py b/app.py index b955f02..620ba26 100644 --- a/app.py +++ b/app.py @@ -23,16 +23,13 @@ def api_root(): @app.route('/device//', methods=["GET", "POST"]) def api_leds_control(device_name): - if request.method == "POST": - # if color in LEDS: - # GPIO.output(LEDS[color], int(request.data.get("state"))) - try: + try: + if request.method == "POST": response = interface_handler.write(device_name,request.data.get("output")) return {'output': response} - except Exception as e: - return {'error': str(e)} - # return {color: GPIO.input(LEDS[color])} - return {'state': interface_handler.read(device_name)} + return {'state': interface_handler.read(device_name)} + except Exception as e: + return {'error': str(e)} if __name__ == "__main__": app.run(port=8080,host="0.0.0.0")