mirror of
https://github.com/simonw/datasette.git
synced 2026-09-27 20:34:08 +02:00
* ruff>=0.16.0 See https://astral.sh/blog/ruff-v0.16.0 * uv run ruff check . --fix --unsafe-fixes * Ruff fixes by Claude Code Opus 5
30 lines
885 B
Python
30 lines
885 B
Python
from datasette import Response, hookimpl
|
|
|
|
from .utils import add_cors_headers
|
|
|
|
|
|
@hookimpl(trylast=True)
|
|
def forbidden(datasette, request, message):
|
|
async def inner():
|
|
if (
|
|
request.path.split("?")[0].endswith(".json")
|
|
or "application/json" in (request.headers.get("accept") or "")
|
|
or request.headers.get("content-type") == "application/json"
|
|
):
|
|
headers = {}
|
|
if datasette.cors:
|
|
add_cors_headers(headers)
|
|
return Response.error(message, 403, headers=headers)
|
|
return Response.html(
|
|
await datasette.render_template(
|
|
"error.html",
|
|
{
|
|
"title": "Forbidden",
|
|
"error": message,
|
|
},
|
|
request=request,
|
|
),
|
|
status=403,
|
|
)
|
|
|
|
return inner
|