Fix for weird nested exception in RequestTimeout

I saw this error:

    sanic.exceptions.RequestTimeout: Request Timeout

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "/Users/simonw/Dropbox/Development/datasette/venv/lib/python3.6/site-packages/sanic/handlers.py", line 82, in response
        response = handler(request=request, exception=exception)
      File "/Users/simonw/Dropbox/Development/datasette/datasette/app.py", line 512, in on_exception
        if request.path.split("?")[0].endswith(".json"):
    AttributeError: 'NoneType' object has no attribute 'path'

Strangely "if request and request.path..." did not work here, because the
Sanic Request class extends builtins.dict and hence evaluates to False if it
has no headers.
This commit is contained in:
Simon Willison 2018-06-29 07:52:51 -05:00
commit d08faa8987
No known key found for this signature in database
GPG key ID: 17E2DEA2588B7F52

View file

@ -509,7 +509,7 @@ class Datasette:
info.update(
{"ok": False, "error": message, "status": status, "title": title}
)
if request.path.split("?")[0].endswith(".json"):
if request is not None and request.path.split("?")[0].endswith(".json"):
return response.json(info, status=status)
else: