File tree 1 file changed +12
-0
lines changed
1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change 1
1
from fastapi import APIRouter
2
2
from fastapi import FastAPI
3
+ from fastapi import Request
3
4
from fastapi .staticfiles import StaticFiles
4
5
from sqlalchemy .orm import Session
6
+ from starlette .responses import RedirectResponse
5
7
6
8
from config import oauth2_config
7
9
from database import Base
8
10
from database import engine
9
11
from database import get_db
12
+ from fastapi_oauth2 .exceptions import OAuth2Error
10
13
from fastapi_oauth2 .middleware import Auth
11
14
from fastapi_oauth2 .middleware import OAuth2Middleware
12
15
from fastapi_oauth2 .middleware import User
@@ -37,6 +40,15 @@ async def on_auth(auth: Auth, user: User):
37
40
38
41
39
42
app = 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
+
40
52
app .include_router (router_api )
41
53
app .include_router (router_ssr )
42
54
app .include_router (oauth2_router )
You can’t perform that action at this time.
0 commit comments