File tree 1 file changed +19
-3
lines changed
1 file changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -131,11 +131,27 @@ the [user context](/integration/integration#user-context) will be available for
131
131
132
132
## Error handling
133
133
134
- ::: info NOTE
134
+ The exceptions that possibly can occur when using the library are reraised as ` HTTPException ` with the appropriate
135
+ status code and a message describing the actual error cause. So they can be handled in a natural way by following the
136
+ FastAPI [ docs] ( https://fastapi.tiangolo.com/tutorial/handling-errors/ ) on handling errors and using the exceptions from
137
+ the ` fastapi_oauth2.exceptions ` module.
135
138
136
- This section is under development.
139
+ ``` python
140
+ from fastapi_oauth2.exceptions import OAuth2AuthenticationError
137
141
138
- :::
142
+ @app.exception_handler (OAuth2AuthenticationError)
143
+ async def error_handler (request : Request, exc : OAuth2AuthenticationError):
144
+ return RedirectResponse(url = " /login" , status_code = 303 )
145
+ ```
146
+
147
+ The complete list of exceptions is the following.
148
+
149
+ - ` OAuth2Error ` - Base exception for all errors raised by the FastAPI OAuth2 library.
150
+ - ` OAuth2AuthenticationError ` - An exception is raised when the authentication fails.
151
+ - ` OAuth2InvalidRequestError ` - An exception is raised when the request is invalid.
152
+
153
+ The request is considered invalid when one of mandatory parameters such as ` state ` or ` code ` is missing or the request
154
+ did not succeed.
139
155
140
156
<style >
141
157
.info , .details {
You can’t perform that action at this time.
0 commit comments