How to integrate FastAPI Users with the Apiexception library #1549
Replies: 1 comment
-
|
This is a great library, and I also noticed that the author of fastapi-users has starred it as well. Since fastapi-users is now in maintenance mode, it’s unlikely that any new features or structural changes will be added to the library. I think the best approach is to rewrite all the FastAPI routers and modify the Python files under the router directory so they fully adopt the APIException pattern. Basically, you can copy and paste the existing router code and then update:
Reference: Once your custom routers are ready, you should create a subclass of FastAPIUsers and override all router methods so the library will use your rewritten routers instead of the original ones. This ensures the entire authentication workflow consistently applies your new response model and exception format. Regarding exception handling: https://github.com/fastapi-users/fastapi-users/blob/master/fastapi_users/exceptions.py If your rewritten routers fully wrap and normalize all error cases, then you might not need to intercept these exceptions anymore. However, if any part of the library still raises its own exceptions internally, you may still need to catch them and convert them into your unified APIException format. It really depends on whether the rewritten routers cover all execution paths. If needed, you can ask an AI tool to help generate the integration code — automating this conversion is pretty straightforward. I just tried modifying the login route, and it seems to work. 20251208_222110.mp4 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Building a unified API return
APIException
Beta Was this translation helpful? Give feedback.
All reactions