added error handling for all requests
This commit is contained in:
parent
37cb64a2ab
commit
9c56c1b2d2
7
app.py
7
app.py
@ -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":
|
|
||||||
# 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"))
|
response = interface_handler.write(device_name,request.data.get("output"))
|
||||||
return {'output': response}
|
return {'output': response}
|
||||||
|
return {'state': interface_handler.read(device_name)}
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return {'error': str(e)}
|
return {'error': str(e)}
|
||||||
# return {color: GPIO.input(LEDS[color])}
|
|
||||||
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")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user