Fallback for route name when no route found.

This commit is contained in:
L. Karkkainen 2023-02-05 16:06:45 +00:00
parent 207f8af11f
commit a6ff13ceed

View File

@ -29,6 +29,10 @@ class ErrorPage(BasePage):
def _body(self) -> None: def _body(self) -> None:
debug = self.request.app.debug debug = self.request.app.debug
try:
route_name = self.request.route.name
except AttributeError:
route_name = "[route not found]"
with self.doc.main: with self.doc.main:
self.doc.h1(f"⚠️ {self.title}").p(self.text) self.doc.h1(f"⚠️ {self.title}").p(self.text)
context = getattr(self.exc, "context", None) or {} context = getattr(self.exc, "context", None) or {}
@ -46,7 +50,7 @@ class ErrorPage(BasePage):
with self.doc.details(open=self.full, class_="smalltext"): with self.doc.details(open=self.full, class_="smalltext"):
self.doc.summary("Details for developers (Sanic debug mode only)") self.doc.summary("Details for developers (Sanic debug mode only)")
if self.exc: if self.exc:
self.doc.h2(f"Exception in {self.request.route.name}:") self.doc.h2(f"Exception in {route_name}:")
# skip_outmost=1 to hide Sanic.handle_request # skip_outmost=1 to hide Sanic.handle_request
self.doc(html_traceback(self.exc, skip_outmost=1, include_js_css=False)) self.doc(html_traceback(self.exc, skip_outmost=1, include_js_css=False))