mirror of https://github.com/tiangolo/fastapi.git
597 B
597 B
Exceptions - HTTPException and WebSocketException
These are the exceptions that you can raise to show errors to the client.
When you raise an exception, as would happen with normal Python, the rest of the execution is aborted. This way you can raise these exceptions from anywhere in the code to abort a request and show the error to the client.
You can use:
HTTPExceptionWebSocketException
These exceptions can be imported directly from fastapi:
from fastapi import HTTPException, WebSocketException
::: fastapi.HTTPException
::: fastapi.WebSocketException