예제 #1
0
 async def __call__(self, environ, on_response):
     request, response = None, None
     try:
         request = await self.create_request(environ)
         response = await self.full_dispatch_request(request)
     except Exception as ex:
         try:
             exception = await self.exception_handler.process_exception(
                 request, ex)
         except IGNORE_EXCEPTIONS:
             response = None
         else:
             if isinstance(exception, self.exception_class):
                 response = exception.get_response()
             elif isinstance(exception, self.response_class):
                 response = exception
             else:
                 response = None
     if not on_response:
         return response
     if response:
         await on_response(response)
     elif not self.is_websocket:
         message = "Caught handled exception, response object empty."
         self.logger.error(message)
         await on_response(
             self.exception_handler.process_exception(
                 request, ServerError(message)).get_response())
예제 #2
0
파일: app.py 프로젝트: dwpy/alita
 async def make_response(self, response):
     if isinstance(response, self.response_class):
         pass
     elif isinstance(response, self.exception_class):
         return response.get_response()
     else:
         raise ServerError(
             'The view function did not return a valid http response. The'
             ' function must returned a statement.')
     return response
예제 #3
0
 async def make_response(self, response):
     if callable(response):
         response = response()
     if isinstance(response, self.response_class):
         pass
     elif isinstance(response, self.exception_class):
         return response.get_response()
     else:
         raise ServerError("Response Object Type invalid!")
     return response
예제 #4
0
파일: app.py 프로젝트: dwpy/alita
 async def full_dispatch_request(self, request):
     try:
         signals.request_started.send(self)
         response = await self.preprocess_request(request)
         if response is None:
             response = await self.dispatch_request(request)
         response = await self.finalize_request(request, response)
         return await self.finalize_response(response)
     except Exception as ex:
         exception = await self.exception_handler.process_exception(
             request, ex)
         if issubclass(type(exception), BaseException):
             raise exception
         try:
             return await self.make_response(exception)
         except ServerError:
             message = "Caught handled exception: %s." % str(exception)
             self.logger.error(message)
             raise ServerError(message)