INNER CODE UNIT · Python

handle_error

sky22333/ansible-ui · app.py:58

def handle_error(f):
    """错误处理装饰器"""
    @wraps(f)
    def decorated_function(*args, **kwargs):
        try:
            return f(*args, **kwargs)
        except Exception as e:
            app.logger.error(f"Error in {f.__name__}: {str(e)}")
            return jsonify({'error': str(e)}), 500
    return decorated_function

def get_request_token():
    """从请求中提取JWT令牌"""
    auth_header = request.headers.get('Authorization', '')
    if auth_header.startswith('Bearer '):
        return auth_header.split(' ', 1)[1]

    return request.cookies.get('token') or request.args.get('token')

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…