Skip to main content

websocket_request_validation_exception_handler

Closes a WebSocket connection with a policy violation code and provides the validation error details as the closure reason.

def websocket_request_validation_exception_handler(
websocket: WebSocket,
exc: WebSocketRequestValidationError
) - > None

Handles WebSocket request validation errors by closing the connection with a policy violation code and a JSON-encoded reason for the failure.

Parameters

NameTypeDescription
websocketWebSocketThe active WebSocket connection instance that encountered the validation error.
excWebSocketRequestValidationErrorThe exception object containing the specific validation errors to be encoded and sent as the closure reason.

Returns

TypeDescription
NoneNothing is returned; the function performs an asynchronous side effect of closing the WebSocket connection.