def doFilter(self, request: Request, response: Response, chain: FilterChain): chain.doFilter(request, response) if self.registry.is_annotated( response.body.__class__, Serializable) or type( response.body) in TYPES_TO_BE_SERIALIZED: response.body = self.serializer.serialize(response.body)
def doFilter(self, request: Request, response: Response, chain: FilterChain): try: chain.doFilter(request, response) except Exception: response.status = 500 response.body = "An error occurred while handling this request." self.LOGGER.error(traceback.format_exc())
def doFilter(self, request: Request, response: Response, chain: FilterChain): if request.headers['Content-Type'] == 'application/json' and len(request.body) > 0: request.body = json.loads(request.body) chain.doFilter(request, response) if isinstance(response.body, dict) or isinstance(response.body, list): response.body = json.dumps(response.body) response.headers['Content-Type'] = 'application/json'
def doFilter(self, request: Request, response: Response, chain: FilterChain): try: chain.doFilter(request, response) except Exception as e: response.status = 500 response.body = "{}\n{}".format(e.__class__.__name__, traceback.format_exc()) self.LOGGER.error(traceback.format_exc())
def doFilter(self, request: Request, response: Response, chain: FilterChain): chain.doFilter(request, response) if isinstance(response.body, RenderedView): rendered_view = response.body template_text = self.view_template_repository.get_template(rendered_view.view_file) template_parameters = rendered_view.data if self.deserializer.is_deserializable_type(rendered_view.data.__class__): template_parameters = self.serializer.serialize(rendered_view.data) response.body = Template(template_text).render(**template_parameters) response.headers['Content-Type'] = "text/html"