WebSocket

WebSocket 1007 Invalid Payload Data vs 1011 Internal Error

Both WebSocket 1007 (Invalid Payload Data) and 1011 (Internal Error) belong to the WebSocket Close Codes category. 1007 indicates that an endpoint received a message with payload data that is inconsistent with the message type. For example, a text message contained non-UTF-8 data. Meanwhile, 1011 means that the server is terminating the connection because it encountered an unexpected condition that prevented it from fulfilling the request.

Описание

An endpoint received a message with payload data that is inconsistent with the message type. For example, a text message contained non-UTF-8 data.

Когда вы это видите

A text frame was received but its payload is not valid UTF-8. This commonly happens when binary data is accidentally sent as a text frame.

Как исправить

Ensure text frames contain only valid UTF-8 encoded data. If you need to send raw bytes, use binary frames instead of text frames.

Описание

The server is terminating the connection because it encountered an unexpected condition that prevented it from fulfilling the request.

Когда вы это видите

The server hit an unhandled exception or crashed while processing a WebSocket message. This is the WebSocket equivalent of HTTP 500 Internal Server Error.

Как исправить

Check the server-side application logs for stack traces and exceptions. Fix the underlying bug that caused the crash and add proper error handling around message processing.

Ключевые различия

1.

WebSocket 1007: An endpoint received a message with payload data that is inconsistent with the message type. For example, a text message contained non-UTF-8 data.

2.

WebSocket 1011: The server is terminating the connection because it encountered an unexpected condition that prevented it from fulfilling the request.

3.

You encounter 1007 when a text frame was received but its payload is not valid UTF-8. This commonly happens when binary data is accidentally sent as a text frame.

4.

You encounter 1011 when the server hit an unhandled exception or crashed while processing a WebSocket message. This is the WebSocket equivalent of HTTP 500 Internal Server Error.

Когда что использовать

For 1007 (Invalid Payload Data): Ensure text frames contain only valid UTF-8 encoded data. If you need to send raw bytes, use binary frames instead of text frames. For 1011 (Internal Error): Check the server-side application logs for stack traces and exceptions. Fix the underlying bug that caused the crash and add proper error handling around message processing.

Узнать больше