mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Return method not allowed error in JSON in some situations
Added this while playing with the new API explorer, refs #1871
This commit is contained in:
parent
000eeb4464
commit
719e757252
1 changed files with 11 additions and 5 deletions
|
|
@ -69,20 +69,26 @@ class BaseView:
|
|||
def database_color(self, database):
|
||||
return "ff0000"
|
||||
|
||||
async def options(self, request, *args, **kwargs):
|
||||
async def method_not_allowed(self, request):
|
||||
print(request.headers)
|
||||
if request.path.endswith(".json") or request.headers.get("content-type") == "application/json":
|
||||
return Response.json({"ok": False, "error": "Method not allowed"}, status=405)
|
||||
return Response.text("Method not allowed", status=405)
|
||||
|
||||
async def options(self, request, *args, **kwargs):
|
||||
return await self.method_not_allowed(request)
|
||||
|
||||
async def post(self, request, *args, **kwargs):
|
||||
return Response.text("Method not allowed", status=405)
|
||||
return await self.method_not_allowed(request)
|
||||
|
||||
async def put(self, request, *args, **kwargs):
|
||||
return Response.text("Method not allowed", status=405)
|
||||
return await self.method_not_allowed(request)
|
||||
|
||||
async def patch(self, request, *args, **kwargs):
|
||||
return Response.text("Method not allowed", status=405)
|
||||
return await self.method_not_allowed(request)
|
||||
|
||||
async def delete(self, request, *args, **kwargs):
|
||||
return Response.text("Method not allowed", status=405)
|
||||
return await self.method_not_allowed(request)
|
||||
|
||||
async def dispatch_request(self, request):
|
||||
if self.ds:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue