Error Codes
The WebSocket may close the connection with specific error codes. In addition to standard WebSocket codes, VoxFi uses custom codes in the 4000-4999 range.VoxFi Custom Codes
4001 - Unauthorized
Cause: Invalid or missing API key when trying to subscribe to theuser channel.
When it occurs: When trying to subscribe to the user channel without providing auth or with an invalid API key.
Solution:
- Verify that you are providing the
authfield in the subscribe message; - Confirm that the API key is correct and active;
- Check if the API key has expired or been disabled;
- Verify that your IP is on the API key’s whitelist.
4002 - Invalid Params
Cause: Invalid connection parameters. When it occurs: During initial connection validation, when session data is invalid or missing. Common error messages:"session is required": Invalid or missing session
4003 - Server Error
Cause: Internal server error. When it occurs: When an unexpected error occurs on the server while processing your request. Solution: Try again after a few seconds. If the problem persists, contact support.4004 - Invalid Message
Cause: Invalid message or incorrect parameters in the subscribe/unsubscribe message. When it occurs: When sending messages with invalid format or content. Possible causes:- Invalid
channelfield (must be"user","market"or"event"); - Invalid
filterfield (must be"all","orderbook","trades"or empty); - Missing required fields (
marketsfor market channel,eventsfor event channel,authfor user channel); - Invalid JSON format;
- Invalid message type (must be
"subscribe"or"unsubscribe").
"invalid channel": Specified channel does not exist;"invalid filter": Specified filter is invalid;"invalid message type": Invalid message type.
Standard WebSocket Codes
In addition to custom codes, the WebSocket may return standard codes:- 1000: Normal closure (not an error);
- 1001: Endpoint going away;
- 1002: Protocol error;
- 1006: Connection closed abnormally (without close code);
- 1011: Internal server error.
Error Handling
Error Messages
In addition to close codes, the WebSocket returns error messages in thereason field when closing the connection. These messages provide specific details about the error:
Common Error Messages
"session is required"(code 4002): Invalid or missing session during initial validation;"invalid channel"(code 4004): Specified channel does not exist (must be"user","market"or"event");"invalid filter"(code 4004): Specified filter is invalid (must be"all","orderbook","trades"or empty);"invalid message type"(code 4004): Invalid message type (must be"subscribe"or"unsubscribe");"failed to check x-api-key"(code 4001): Failed to validate API key;- Go JSON error messages when there is a failure to unmarshal the message (code 4004).
Error Handling Best Practices
- Always Handle onclose: Implement handling for the
oncloseevent to detect disconnections; - Check Error Codes: Use error codes to determine the cause and take appropriate actions;
- Smart Reconnection: Implement automatic reconnection with exponential backoff for temporary errors;
- Don’t Reconnect for Permanent Errors: Errors like 1003 (unauthorized) or 1008 (invalid message) indicate problems that need to be fixed before reconnecting;
- Logging: Log all errors for debugging and monitoring;
- Pre-validation: Validate messages before sending to avoid 1008 errors;
- Timeout Handling: Implement timeout for connections that don’t respond.

