# Path: drift/core/extensions/jwt.py
# def query_current_user():
#     """
#     Return the current jwt payload if the user has been authenticated
#     """
#     return getattr(_request_ctx_stack.top, 'drift_jwt_payload', None)
# 
# def jwt_not_required(fn):
#     log.debug("Registering open endpoint in module : %s", fn.__module__)
#     _open_endpoints.add(fn)
#     return fn


import logging
import json
import uuid
import traceback
import sys
from six import StringIO
from flask import make_response, jsonify, request, current_app
from werkzeug.exceptions import HTTPException
from flask_smorest import abort
from drift.core.extensions.jwt import query_current_user, jwt_not_required

    # Borko endpoint. Always fails.
    @jwt_not_required
    @app.route('/borko', methods=['GET', 'POST'])
    def borko_handler():
        data = request.get_json()
        if data:
            status_code = data.pop('status_code', 400)
            abort(int(status_code), **data)
        else:
            raise RuntimeError("Borko raising an error.")


def handle_all_exceptions(e):
    is_server_error = not isinstance(e, HTTPException)

    ret = {}
    error = {}
    ret['error'] = error

    if is_server_error or e.code >= 500:
        # Use context_id from the client if it's available, or make one if not.
        log_context = request.headers.get("Drift-Log-Context")
        log_context = json.loads(log_context) if log_context else {}
        context_id = log_context.get("request_id", str(uuid.uuid4()).replace("-", ""))
        error['context_id'] = context_id
        title = str(e) + " - [{}]".format(context_id)

    if is_server_error:
        # Do a traceback if caller has dev role, or we are running in debug mode.

# Path: drift/core/extensions/jwt.py
# def query_current_user():
#     """
#     Return the current jwt payload if the user has been authenticated
#     """
#     return getattr(_request_ctx_stack.top, 'drift_jwt_payload', None)
# 
# def jwt_not_required(fn):
#     log.debug("Registering open endpoint in module : %s", fn.__module__)
#     _open_endpoints.add(fn)
#     return fn


# Path: drift/core/extensions/apierrors.py
import logging
import json
import uuid
import traceback
import sys
from six import StringIO
from flask import make_response, jsonify, request, current_app
from werkzeug.exceptions import HTTPException
from flask_smorest import abort
from drift.core.extensions.jwt import query_current_user, jwt_not_required


    # Borko endpoint. Always fails.
    @jwt_not_required
    @app.route('/borko', methods=['GET', 'POST'])
    def borko_handler():
        data = request.get_json()
        if data:
            status_code = data.pop('status_code', 400)
            abort(int(status_code), **data)
        else:
            raise RuntimeError("Borko raising an error.")


def handle_all_exceptions(e):
    is_server_error = not isinstance(e, HTTPException)

    ret = {}
    error = {}
    ret['error'] = error

    if is_server_error or e.code >= 500:
        # Use context_id from the client if it's available, or make one if not.
        log_context = request.headers.get("Drift-Log-Context")
        log_context = json.loads(log_context) if log_context else {}
        context_id = log_context.get("request_id", str(uuid.uuid4()).replace("-", ""))
        error['context_id'] = context_id
        title = str(e) + " - [{}]".format(context_id)

    if is_server_error:
        # Do a traceback if caller has dev role, or we are running in debug mode.

        current_user = query_current_user()