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"]) | ||||
| def api_leds_control(device_name): | ||||
|     if request.method == "POST": | ||||
|         # if color in LEDS: | ||||
|         #     GPIO.output(LEDS[color], int(request.data.get("state"))) | ||||
|     try: | ||||
|         if request.method == "POST": | ||||
|             response = interface_handler.write(device_name,request.data.get("output")) | ||||
|             return {'output': response} | ||||
|         return {'state': interface_handler.read(device_name)} | ||||
|     except Exception as e: | ||||
|         return {'error': str(e)} | ||||
|     # return {color: GPIO.input(LEDS[color])} | ||||
|     return {'state': interface_handler.read(device_name)} | ||||
| 
 | ||||
| if __name__ == "__main__": | ||||
|     app.run(port=8080,host="0.0.0.0") | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 p.loedige
						p.loedige