from flask import request
from flask_restful import Resource, abort

from app.state import state


class PostProgram(Resource):

    def post(self, program_name):
            args = request.args

            if 'brigthness' in args:
                if not 0 <= float(args['brightness']) <= 1:
                    abort(404, error="Brigthness must be a float between 0 and 1")

            if 'rotation' in args:
                print(args['rotation'])
                if not int(args['rotation']) in [0, 90, 180, 270]:
                    abort(404, error="Rotation must be 0, 90, 180, or 270 degrees")

            state.start_program(program_name, args)
@@ -205,323 +205,105 @@
     
-if 'brigthness' in args:%0A                if not 0 %3C= float(args%5B'brightness'%5D) %3C= 1:%0A                    abort(404, error=%22Brigthness must be a float between 0 and 1%22)%0A%0A            if 'rotation' in args:%0A                print(args%5B'rotation'%5D)%0A                if not int(args%5B'rotation'%5D) in %5B0, 90, 180, 270%5D:%0A    
+try:%0A                state.start_program(program_name, args)%0A            except ValueError as e:%0A
     
@@ -326,17 +326,17 @@
 t(40
-4
+0
 , error=
 %22Rot
@@ -335,103 +335,11 @@
 ror=
-%22Rotation must be 0, 90, 180, or 270 degrees%22)%0A%0A            state.start_program(program_name, args
+str(e)
 )

Refactor api error handling