The PubSub docs mention the following about the error messages you can get surrounding subscribing to events:
For Bits and whispers events requests, error responses can be: ERR_BADMESSAGE, ERR_BADAUTH, ERR_SERVER, ERR_BADTOPIC.
This is simply not true. Not only are there other error messages you can also get not listed here, but I also can’t seem to reproduce ERR_BADMESSAGE at all (and ERR_BADTOPIC is replaced by another message).
The following are some test cases with expected and actual results.
Test Cases
(1) Invalid JSON (Single quotes surrounding string)
SENT: {"data":{"auth_token":"<valid_auth>","topics":['channel-bits-events-v2.<valid_channel>']},"nonce":"asdka","type":"LISTEN"}`
Expected: {"type":"RESPONSE","error":"ERR_BADMESSAGE","nonce":"asdka"}
Actual: No response
(2) Empty topics array
SENT: {"data":{"auth_token":"<valid_auth>","topics":[]},"nonce":"asdka","type":"LISTEN"}
Expected: {"type":"RESPONSE","error":"ERR_BADMESSAGE","nonce":"asdka"} (or ERR_BADTOPIC)
Actual: {"type":"RESPONSE","error":"unexpected http status 400","nonce":"asdka"}
(3) Attempting to unsubscribe from a topic not currently subscribed
This one is debatable whether it should respond with an error or not, but I included it as the behavior is not documented.
SENT: {"data":{"auth_token":"<valid_auth>","topics":["channel-bits-events-v2.123"]},"nonce":"asdka","type":"UNLISTEN"}
Expected: {"type":"RESPONSE","error":"ERR_BADTOPIC","nonce":"asdka"}
Actual: {"type":"RESPONSE","error":"","nonce":"asdka"}
(4) Attempting to subscribe to a topic with no channel id (with and without dot)
SENT: {"data":{"auth_token":"<valid_auth>","topics":["channel-bits-events-v2."]},"nonce":"asdka","type":"LISTEN"}
Expected: {"type":"RESPONSE","error":"ERR_BADTOPIC","nonce":"asdka"}
Actual: {"type":"RESPONSE","error":"Invalid Topic","nonce":"asdka"}
SENT: {"data":{"auth_token":"<valid_auth>","topics":["channel-bits-events-v2"]},"nonce":"asdka","type":"LISTEN"}
Expected: {"type":"RESPONSE","error":"ERR_BADTOPIC","nonce":"asdka"}
Actual: {"type":"RESPONSE","error":"Invalid Topic","nonce":"asdka"}
(5) Attempting to subscribe to a non-existent topic
Note that the channel ID doesn’t matter at all here.
SENT: {"data":{"auth_token":"<valid_auth>","topics":["channel-bits-ev"]},"nonce":"asdka","type":"LISTEN"}
Expected: {"type":"RESPONSE","error":"ERR_BADTOPIC","nonce":"asdka"}
Actual: {"type":"RESPONSE","error":"Invalid Topic","nonce":"asdka"}
(6) Bad request type
SENT: {"data":{"auth_token":"<valid_auth>","topics":["channel-bits-events-v2.<valid_channel>"]},"nonce":"asdka","type":"LSTEN"}
Expected: {"type":"RESPONSE","error":"ERR_BADMESSAGE","nonce":"asdka"}
Actual: No response
(7) Extra parameters
This is also debatable on whether it should continue working or throw an error, but again I included because the behavior is not documented (and is inconsistent, see test case 8).
SENT: {"data":{"auth_token":"<valid_auth>","topics":["channel-bits-events-v2.<valid_channel>"]},"nounce":"asdka","type":"LISTEN"}
Expected: {"type":"RESPONSE","error":"ERR_BADMESSAGE","nonce":""}
Actual: {"type":"RESPONSE","error":"","nonce":""}
(8) Bad nonce
Note that these examples are valid JSON, so the fact that this does not just ignore the nonce like test case 7 above makes for somewhat inconsistent behavior.
SENT: {"data":{"auth_token":"<valid_auth>","topics":["channel-bits-events-v2.<valid_channel>"]},"nonce": true,"type":"LISTEN"}
Expected: {"type":"RESPONSE","error":"ERR_BADMESSAGE","nonce":""}
Actual: No response
SENT: {"data":{"auth_token":"<valid_auth>","topics":["channel-bits-events-v2.<valid_channel>"]},"nonce":1234,"type":"LISTEN"}
Expected: {"type":"RESPONSE","error":"ERR_BADMESSAGE","nonce":""}
Actual: No response