# Error Handling

## Connection Error Codes

| Status | Code              | Reason                      | Resolution                         |
| ------ | ----------------- | --------------------------- | ---------------------------------- |
| 400    | Bad Request       | Invalid `customerid` format | Use numeric characters only        |
| 401    | Unauthorized      | Missing `customerid` header | Add `customerid` to `extraHeaders` |
| 402    | Payment Required  | Account inactive or expired | Contact LSports support            |
| 403    | Forbidden         | Customer ID not found       | Verify your Customer ID            |
| 429    | Too Many Requests | Rate limit exceeded         | Wait before reconnecting           |
| 500    | Internal Error    | Server error                | Retry with backoff                 |

***

## Error Response Handling

```javascript
socket.on("connect_error", (error) => {
  console.error("Connection error:", error.message);

  const statusCode = error.data?.statusCode;

  switch (statusCode) {
    case 400:
      console.error("Invalid customerid format — use numeric characters only");
      break;
    case 401:
      console.error("Missing customerid header — add it to extraHeaders");
      break;
    case 402:
      console.error("Account inactive or expired — contact LSports support");
      break;
    case 403:
      console.error("Customer not authorized — verify your Customer ID");
      break;
    case 429:
      console.error("Rate limited — wait before retrying");
      break;
    default:
      console.error("Connection failed — will retry:", error.message);
  }
});
```

***

## WebSocket Close Codes

| Code | Reason                              |
| ---- | ----------------------------------- |
| 1000 | Normal closure                      |
| 1001 | Server going away (maintenance)     |
| 4401 | Authentication failed after upgrade |
| 4403 | Authorization revoked               |

***

## Troubleshooting

| Issue                       | Possible Cause                    | Solution                               |
| --------------------------- | --------------------------------- | -------------------------------------- |
| `Missing customerid header` | Header not included in connection | Add `customerid` to `extraHeaders`     |
| `Connection timeout`        | Network or firewall issues        | Check connectivity; whitelist WSS port |
| `Invalid customerid format` | Non-numeric customer ID           | Use numeric Customer ID only           |
| `Account inactive`          | Subscription expired              | Contact LSports support                |
| `No messages received`      | Not joined to room                | Emit `join` event after connecting     |

***

## Support

For persistent issues, contact LSports support with:

* Your Customer ID
* Error messages received
* Timestamp of the issue

***

## Related

* [Quick Start & Best Practices](/u/defend/websocket-connection/quick-start-and-best-practices.md)
* [Code Examples](/u/defend/websocket-connection/code-examples.md)
* [Authentication Guide](/u/defend/integration-guide/authentication.md)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.lsports.eu/u/defend/websocket-connection/error-handling.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
