def safe(f):
def wraps(self, *args, **kwargs):<EOL><INDENT>try:<EOL><INDENT>return f(self, *args, **kwargs)<EOL><DEDENT>except BadRequest as e:<EOL><INDENT>return self.response_400(message=str(e))<EOL><DEDENT>except Exception as e:<EOL><INDENT>logging.exception(e)<EOL>return self.response_500(message=get_error_msg())<EOL><DEDENT><DEDENT>return functools.update_wrapper(wraps, f)<EOL>
A decorator that catches uncaught exceptions and
return the response in JSON format (inspired on Superset code)