mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Return HTTP 405 on InvalidUsage rather than 500
This also stops it filling up the logs. This happens for HEAD requests at the moment - which perhaps should be handled better, but that's a different issue.
This commit is contained in:
parent
8d394586f5
commit
efbb4e8337
1 changed files with 5 additions and 1 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
from sanic import Sanic
|
from sanic import Sanic
|
||||||
from sanic import response
|
from sanic import response
|
||||||
from sanic.exceptions import NotFound
|
from sanic.exceptions import NotFound, InvalidUsage
|
||||||
from sanic.views import HTTPMethodView
|
from sanic.views import HTTPMethodView
|
||||||
from sanic.request import RequestParameters
|
from sanic.request import RequestParameters
|
||||||
from jinja2 import Environment, FileSystemLoader, ChoiceLoader, PrefixLoader
|
from jinja2 import Environment, FileSystemLoader, ChoiceLoader, PrefixLoader
|
||||||
|
|
@ -1258,6 +1258,10 @@ class Datasette:
|
||||||
status = 404
|
status = 404
|
||||||
info = {}
|
info = {}
|
||||||
message = exception.args[0]
|
message = exception.args[0]
|
||||||
|
elif isinstance(exception, InvalidUsage):
|
||||||
|
status = 405
|
||||||
|
info = {}
|
||||||
|
message = exception.args[0]
|
||||||
elif isinstance(exception, DatasetteError):
|
elif isinstance(exception, DatasetteError):
|
||||||
status = exception.status
|
status = exception.status
|
||||||
info = exception.error_dict
|
info = exception.error_dict
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue