def technical_404_response(request): "Create a technical 404 error response. The exception should be the Http404." route_path = request.environ['REQUEST_URI'] t = Template(TECHNICAL_404_TEMPLATE) c = { 'route_path': route_path, 'request': request, 'settings': get_safe_settings(), } response = not_found() response.write(t.render(**c)) return response
def get(self): m = attrdict(slug=u(''), fields=['']) if (not self.try_update_model(m, self.route_args) or not self.try_update_model(m, self.request.query) or not self.validate(m, post_spec_validator)): return self.json_errors() p = self.get_post(m.slug, m.fields) if not p: return not_found() r = self.json_response(p) if self.principal: r.cache_dependency = ( keys.post(m.slug), keys.author_comments(self.principal.id)) else: r.cache_dependency = (keys.post_public(m.slug),) return r
def __call__(self, request, following): assert following is not None try: response = following(request) if response is None: response = not_found() except (KeyboardInterrupt, SystemExit, MemoryError): raise except Exception: exc_info = sys.exc_info() extra = self.extra_provider and self.extra_provider(request) or {} self.logger.error( ''.join(format_exception_only(*exc_info[:2])).strip('\n'), exc_info=exc_info, extra=extra) response = internal_error() status_code = response.status_code if status_code >= 400: error_route_name = self.error_mapping[status_code] route_name = request.environ['route_args'].get('route_name') if error_route_name != route_name: response = RedirectRouteHandler(request, error_route_name) return response