Ejemplo n.º 1
0
    def common_error_handler(exception):
        """
        Generally, each route handler should be decorated with @dss_handler, which manages exceptions. The two cases
        that fail are:

        1. handlers that are not decorated.
        2. handlers that return a code that is not in the swagger spec.

        In both cases, the exception would be punted here, and we return this very generic error that also happens to
        bypass all validation.
        """
        problem = {
            'status': requests.codes.server_error,
            'code': "unhandled_exception",
            'title': str(exception),
            'stacktrace': traceback.format_exc(),
        }
        if isinstance(exception, (OAuthProblem, OAuthResponseProblem,
                                  OAuthScopeProblem, Forbidden)):
            problem['status'] = exception.code
            problem['code'] = exception.__class__.__name__
            problem['title'] = exception.description
        return FlaskApi.get_response(
            ConnexionResponse(
                status_code=problem['status'],
                mimetype="application/problem+json",
                content_type="application/problem+json",
                body=problem,
            ))
Ejemplo n.º 2
0
        def _make_response(response):
            from connexion.apis.flask_api import FlaskApi

            mimetype = default_mimetype
            if hasattr(request, 'prom_connexion_content_type'):
                mimetype = request.prom_connexion_content_type

            return FlaskApi.get_response(response, mimetype=mimetype)
Ejemplo n.º 3
0
def error_method_not_allowed(exception):
    return FlaskApi.get_response(
        problem(
            status=exception.code,
            title="Invalid input",
            detail=exception.description,
            headers={"Allow": "POST"},
        ))
Ejemplo n.º 4
0
def common_error_handler(exception=None):
    """
    :type exception: Exception
    """
    if isinstance(exception, ProblemException):
        response = problem(
            status=exception.status,
            title=exception.title,
            detail=exception.detail,
            type=exception.type,
            instance=exception.instance,
            headers=exception.headers,
            ext=exception.ext,
        )
    else:
        if not isinstance(exception, HTTPException):
            exception = InternalServerError()

        response = problem(title=exception.name, detail=exception.description, status=exception.code, headers=exception.get_headers())

    return FlaskApi.get_response(response)
Ejemplo n.º 5
0
        def wrapper(request):
            try:
                return origwrapper(request)
            except DSSBindingException as ex:
                status = ex.status
                code = ex.code
                title = ex.message
                stacktrace = traceback.format_exc()

                return FlaskApi.get_response(
                    ConnexionResponse(
                        status_code=status,
                        mimetype="application/problem+json",
                        content_type="application/problem+json",
                        body={
                            'status': status,
                            'code': code,
                            'title': title,
                            'stacktrace': stacktrace,
                        },
                    ))
Ejemplo n.º 6
0
    def handle_offer_mgr_exception(exc) -> flask.Response:
        response = connexion.problem(status=400, title=exc.message, detail=exc.detail)

        return FlaskApi.get_response(response)
Ejemplo n.º 7
0
 def verify_request_flask(self) -> Optional[Response]:
     """Verify request with token authentication and return a flask compatible response"""
     res = self.verify_request()
     if res:
         return FlaskApi.get_response(res)
     return None