Relative Content

Tag Archive for pythonpython-3.xfastapimiddlewarestarlette

How to raise custom exceptions in a FastAPI middleware?

I have a simple FastAPI setup with a custom middleware class inherited from BaseHTTPMiddleware. Inside this middleware class, I need to terminate the execution flow under certain conditions. So, I created a custom exception class named CustomError and raised the exception.