Skip to content

Commit

Permalink
Return HTTP 405 on InvalidUsage rather than 500
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
russss authored and Simon Willison committed Apr 14, 2018
1 parent 8d39458 commit efbb4e8
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion datasette/app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from sanic import Sanic
from sanic import response
from sanic.exceptions import NotFound
from sanic.exceptions import NotFound, InvalidUsage
from sanic.views import HTTPMethodView
from sanic.request import RequestParameters
from jinja2 import Environment, FileSystemLoader, ChoiceLoader, PrefixLoader
Expand Down Expand Up @@ -1258,6 +1258,10 @@ def on_exception(request, exception):
status = 404
info = {}
message = exception.args[0]
elif isinstance(exception, InvalidUsage):
status = 405
info = {}
message = exception.args[0]
elif isinstance(exception, DatasetteError):
status = exception.status
info = exception.error_dict
Expand Down

0 comments on commit efbb4e8

Please sign in to comment.