Make get_current_admin error to 401 and add 401 error page.

This commit is contained in:
long2ice
2021-08-31 11:27:23 +08:00
parent 2fcbc814de
commit e99d673191
5 changed files with 44 additions and 3 deletions

View File

@ -6,7 +6,12 @@ from fastapi import FastAPI
from starlette.middleware.cors import CORSMiddleware
from starlette.responses import RedirectResponse
from starlette.staticfiles import StaticFiles
from starlette.status import HTTP_403_FORBIDDEN, HTTP_404_NOT_FOUND, HTTP_500_INTERNAL_SERVER_ERROR
from starlette.status import (
HTTP_401_UNAUTHORIZED,
HTTP_403_FORBIDDEN,
HTTP_404_NOT_FOUND,
HTTP_500_INTERNAL_SERVER_ERROR,
)
from tortoise.contrib.fastapi import register_tortoise
from examples import settings
@ -18,6 +23,7 @@ from fastapi_admin.exceptions import (
forbidden_error_exception,
not_found_error_exception,
server_error_exception,
unauthorized_error_exception,
)
@ -36,6 +42,7 @@ def create_app():
admin_app.add_exception_handler(HTTP_500_INTERNAL_SERVER_ERROR, server_error_exception)
admin_app.add_exception_handler(HTTP_404_NOT_FOUND, not_found_error_exception)
admin_app.add_exception_handler(HTTP_403_FORBIDDEN, forbidden_error_exception)
admin_app.add_exception_handler(HTTP_401_UNAUTHORIZED, unauthorized_error_exception)
@app.on_event("startup")
async def startup():