File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change 11from fastapi import APIRouter
22from fastapi import FastAPI
3+ from fastapi import Request
34from fastapi .staticfiles import StaticFiles
45from sqlalchemy .orm import Session
6+ from starlette .responses import RedirectResponse
57
68from config import oauth2_config
79from database import Base
810from database import engine
911from database import get_db
12+ from fastapi_oauth2 .exceptions import OAuth2Error
1013from fastapi_oauth2 .middleware import Auth
1114from fastapi_oauth2 .middleware import OAuth2Middleware
1215from fastapi_oauth2 .middleware import User
@@ -37,6 +40,15 @@ async def on_auth(auth: Auth, user: User):
3740
3841
3942app = FastAPI ()
43+
44+
45+ # https://fastapi.tiangolo.com/tutorial/handling-errors/
46+ @app .exception_handler (OAuth2Error )
47+ async def error_handler (request : Request , e : OAuth2Error ):
48+ print ("An error occurred in OAuth2Middleware" , e )
49+ return RedirectResponse (url = "/" , status_code = 303 )
50+
51+
4052app .include_router (router_api )
4153app .include_router (router_ssr )
4254app .include_router (oauth2_router )
You can’t perform that action at this time.
0 commit comments