Error code: 40000 - Bad request

If you see this error, it means that the request you have sent to Ably cannot be understood by our servers. This typically happens if you have a malformed request which does not match one of the structures our servers expect.

Examples of specific 4000 errors are as follows:

Unable to publish in Suspended state

If you see this as the reason for a 40000 error it means the clients connection is in a suspended state when an attempt to publish a message was made. See the Available connection states documentation on information on what the suspended connection state means


Unable to read from transport: msg=invalid websocket message (decode failure)

While it is uncommon to encounter this error when utilizing an Ably SDK, it has been reported in scenarios involving custom serialization settings within the .NET SDK. Specifically, this issue arises when the custom serialization is configured to serialize enums as strings and is set as the default serialization method. For example:
public static readonly JsonSerializerSettings AppSerializerSettings = new()

{

Converters = newList<JsonConverter> { newStringEnumConverter() },


};


JsonConvert.DefaultSettings = () => AppSerializerSettings;
This leads to the protocol message being incorrectly formatted as a string. For instance, the action property, which should be represented as an integer, ends up being transmitted as a string instead.
{"action":"Message","channel":"your-channel","msgSerial":0,"messages":[{"name":"my_event","data":"{\"name\":\"{\\\"myBool\\\":false,\\\"myId\\\":\\\"22706081-8ae5-4a4b-931f-910cb29aa9c1\\\",\\\"myResult\\\":\\\"Failed\\\"}\",\"encoding\":\"json\"}","encoding":"json"}]}

instead of being represented as an integer as expected

{"action":15,"channel":"your-channel","msgSerial":0,"messages":[{"name":"my_event","data":"{\"name\":\"{\\\"myBool\\\":false,\\\"myId\\\":\\\"22706081-8ae5-4a4b-931f-910cb29aa9c1\\\",\\\"myResult\\\":\\\"Failed\\\"}\",\"encoding\":\"json\"}","encoding":"json"}]}