WebSocket 1008 Policy Violation vs 1014 Bad Gateway
Both WebSocket 1008 (Policy Violation) and 1014 (Bad Gateway) belong to the WebSocket Close Codes category. 1008 indicates that an endpoint is terminating the connection because it received a message that violates its policy. This is a generic code when none of the other codes (1003, 1009) are suitable. Meanwhile, 1014 means that the server acting as a gateway or proxy received an invalid response from an upstream server it accessed while attempting to fulfill the request.
描述
An endpoint is terminating the connection because it received a message that violates its policy. This is a generic code when none of the other codes (1003, 1009) are suitable.
何时出现
The server rejected a message because it violated an application-level policy — for example, sending messages too rapidly, exceeding rate limits, or failing authentication after the handshake.
如何修复
Review the server's documented policies and constraints. Check for rate limiting, authentication token expiry, or forbidden message content that triggered the rejection.
描述
The server acting as a gateway or proxy received an invalid response from an upstream server it accessed while attempting to fulfill the request.
何时出现
A reverse proxy or API gateway tried to establish a WebSocket connection to a backend server but received an invalid or no response. The upstream server may be down or misconfigured.
如何修复
Check the health of the upstream/backend WebSocket server. Verify the proxy configuration routes WebSocket upgrade requests correctly and that the backend is listening on the expected port.
主要区别
WebSocket 1008: An endpoint is terminating the connection because it received a message that violates its policy. This is a generic code when none of the other codes (1003, 1009) are suitable.
WebSocket 1014: The server acting as a gateway or proxy received an invalid response from an upstream server it accessed while attempting to fulfill the request.
You encounter 1008 when the server rejected a message because it violated an application-level policy — for example, sending messages too rapidly, exceeding rate limits, or failing authentication after the handshake.
You encounter 1014 when a reverse proxy or API gateway tried to establish a WebSocket connection to a backend server but received an invalid or no response. The upstream server may be down or misconfigured.
何时使用哪个
For 1008 (Policy Violation): Review the server's documented policies and constraints. Check for rate limiting, authentication token expiry, or forbidden message content that triggered the rejection. For 1014 (Bad Gateway): Check the health of the upstream/backend WebSocket server. Verify the proxy configuration routes WebSocket upgrade requests correctly and that the backend is listening on the expected port.