@@ -43,6 +43,7 @@ chan.trigger("client-test", data: ["test": "some value"])
43
43
* [ Binding to events] ( #binding-to-events )
44
44
* [ Globally] ( #global-events )
45
45
* [ Per-channel] ( #per-channel-events )
46
+ * [ Receiving errors] ( #receiving-errors )
46
47
* [ Presence channel specifics] ( #presence-channel-specifics )
47
48
* [ Testing] ( #testing )
48
49
* [ Communication] ( #communication )
@@ -258,6 +259,45 @@ myChannel.bind("new-price", callback: { (data: AnyObject?) -> Void in
258
259
})
259
260
```
260
261
262
+ ### Receiving errors
263
+
264
+ Errors are sent to the client for which they are relevant with an event name of ` pusher:error ` . These can be received and handled using code as follows. Obviously the specifics of how to handle them are left up to the developer but this displays the general pattern.
265
+
266
+ ``` swift
267
+ pusher.bind ({ (message : AnyObject ? ) in
268
+ if let message = message as? [String : AnyObject ], eventName = message[" event" ] as? String where eventName == " pusher:error" {
269
+ if let data = message[" data" ] as? [String : AnyObject ], errorMessage = data[" message" ] as? String {
270
+ print (" Error message: \( errorMessage ) " )
271
+ }
272
+ }
273
+ })
274
+ ```
275
+
276
+ The sort of errors you might get are:
277
+
278
+ ``` bash
279
+ # if attempting to subscribe to an already subscribed-to channel
280
+
281
+ " {\" event\" :\" pusher:error\" ,\" data\" :{\" code\" :null,\" message\" :\" Existing subscription to channel presence-channel\" }}"
282
+
283
+ # if the auth signature generated by your auth mechanism is invalid
284
+
285
+ " {\" event\" :\" pusher:error\" ,\" data\" :{\" code\" :null,\" message\" :\" Invalid signature: Expected HMAC SHA256 hex digest of 200557.5043858:presence-channel:{\\\" user_id\\\" :\\\" 200557.5043858\\\" }, but got 8372e1649cf5a45a2de3cd97fe11d85de80b214243e3a9e9f5cee502fa03f880\" }}"
286
+ ```
287
+
288
+ You can see that the general form they take is:
289
+
290
+ ``` bash
291
+ {
292
+ " event" : " pusher:error" ,
293
+ " data" : {
294
+ " code" : null,
295
+ " message" : " Error message here"
296
+ }
297
+ }
298
+ ```
299
+
300
+
261
301
### Unbind event handlers
262
302
263
303
You can remove previously-bound handlers from an object by using the ` unbind ` function. For example,
0 commit comments