Пример #1
0
    async def resolve(self,
                      request: IRequest) -> BaseMatchInfo:  # type: ignore
        '''
        Resolve a request
        '''
        # prevent: https://github.com/aio-libs/aiohttp/issues/3335
        request.url

        request.record('start')
        result = None
        try:
            result = await self.real_resolve(request)
        except (response.Response,
                aiohttp.web_exceptions.HTTPException) as exc:
            await abort()
            return BasicMatchInfo(request, exc)
        except Exception:
            logger.error("Exception on resolve execution",
                         exc_info=True,
                         request=request)
            await abort()
            return BasicMatchInfo(request, response.HTTPInternalServerError())

        if result is not None:
            return result
        else:
            await abort()
            return BasicMatchInfo(request, response.HTTPNotFound())
Пример #2
0
    async def resolve(self,
                      request: IRequest) -> BaseMatchInfo:  # type: ignore
        """
        Resolve a request
        """
        request.record("start")
        result = None
        try:
            result = await self.real_resolve(request)
        except response.Response as exc:
            await abort()
            return BasicMatchInfo(request, exc)
        except asyncio.CancelledError:
            logger.info("Request cancelled", request=request)
            await abort()
            return BasicMatchInfo(request, response.HTTPClientClosedRequest())
        except Exception:
            logger.error("Exception on resolve execution",
                         exc_info=True,
                         request=request)
            await abort()
            return BasicMatchInfo(request, response.HTTPInternalServerError())

        if result is not None:
            return result
        else:
            await abort()
            return BasicMatchInfo(request, response.HTTPNotFound())
Пример #3
0
def generate_error_response(e, request, error, status=500):
    # We may need to check the roles of the users to show the real error
    eid = uuid.uuid4().hex
    http_response = query_adapter(
        e, IErrorResponseException, kwargs={
            'error': error,
            'eid': eid
        })
    if http_response is not None:
        return http_response
    message = _('Error on execution of view') + ' ' + eid
    logger.error(message, exc_info=e, eid=eid, request=request)
    return response.HTTPInternalServerError(content={
        'message': message,
        'reason': error_reasons.UNKNOWN.name,
        'details': error_reasons.UNKNOWN.details,
        'eid': eid
    })
Пример #4
0
 def generate_error_response(self, e, request, error, status=500):
     # We may need to check the roles of the users to show the real error
     eid = uuid.uuid4().hex
     if isinstance(e, asyncio.CancelledError):  # pragma: no cover
         message = _("Cancelled execution of view") + " " + eid
         logger.warning(message, exc_info=e, eid=eid, request=request)
     else:
         message = _("Error on execution of view") + " " + eid
         logger.error(message, exc_info=e, eid=eid, request=request)
     data = {
         "message": message,
         "reason": error_reasons.UNKNOWN.name,
         "details": error_reasons.UNKNOWN.details,
         "eid": eid,
     }
     if app_settings.get("debug"):
         data["traceback"] = traceback.format_exc()
     return response.HTTPInternalServerError(content=data)
Пример #5
0
def generate_error_response(e, request, error, status=500):
    # We may need to check the roles of the users to show the real error
    eid = uuid.uuid4().hex
    http_response = query_adapter(e,
                                  IErrorResponseException,
                                  kwargs={
                                      "error": error,
                                      "eid": eid
                                  })
    if http_response is not None:
        return http_response
    message = _("Error on execution of view") + " " + eid
    logger.error(message, exc_info=e, eid=eid, request=request)
    data = {
        "message": message,
        "reason": error_reasons.UNKNOWN.name,
        "details": error_reasons.UNKNOWN.details,
        "eid": eid,
    }
    if app_settings.get("debug"):
        data["traceback"] = traceback.format_exc()
    return response.HTTPInternalServerError(content=data)
Пример #6
0
    async def resolve(self, request: IRequest) -> MatchInfo:
        '''
        Resolve a request
        '''
        request.record('start')
        result = None
        try:
            result = await self.real_resolve(request)
        except (response.Response, aiohttp.web_exceptions.HTTPException) as exc:
            await abort(request)
            return BasicMatchInfo(request, exc)
        except Exception:
            logger.error("Exception on resolve execution",
                         exc_info=True, request=request)
            await abort(request)
            return BasicMatchInfo(
                request, response.HTTPInternalServerError())

        if result is not None:
            return result
        else:
            await abort(request)
            return BasicMatchInfo(request, response.HTTPNotFound())