def return_validator_error(section): def decorator(func): def wrapped(*args, **kwargs): try: return func(*args, **kwargs) except pyiv.CheckerResult as e: cherrypy.response.status=400 return { "error_type":"RequestValidation", "section":section, "errors":e.error_msg(), } return wrapped return decorator @return_validator_error("ref") def api_edit(self, ref = None, values = None ): fake_delay() json = cherrypy.request.json if ref is None: ref = validator_ref( json["ref"] ).values return "actual result"