From d73a6b7730187a13c4542304ee5567b8cf71ab35 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Tue, 11 Apr 2017 09:01:04 +0100 Subject: [PATCH] Add basic 404 handler --- lantern/main.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lantern/main.py b/lantern/main.py index 1561b07..c17dff8 100644 --- a/lantern/main.py +++ b/lantern/main.py @@ -1,5 +1,6 @@ from sanic import Sanic -from sanic.response import json +from sanic.response import json, text +from sanic.exceptions import NotFound app = Sanic() @@ -8,5 +9,10 @@ async def test(request): return json({"hello": "world"}) +@app.exception(NotFound) +def ignore_404s(request, exception): + return text("Page not found at {}".format(request.url), status=404) + + def main(): app.run(host="0.0.0.0", port="8000")