Skip to content

Commit 03002ae

Browse files
authored
Merge pull request #284 from laravel/subscription-errors
Implement error handling
2 parents 248d6ff + 89deb5b commit 03002ae

File tree

4 files changed

+33
-3
lines changed

4 files changed

+33
-3
lines changed

src/channel/channel.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,14 @@ export abstract class Channel {
3232
abstract stopListening(event: string): Channel;
3333

3434
/**
35-
* Stop listening for a whispser event on the channel instance.
35+
* Stop listening for a whisper event on the channel instance.
3636
*/
3737
stopListeningForWhisper(event: string): Channel {
3838
return this.stopListening('.client-' + event);
3939
}
40+
41+
/**
42+
* Register a callback to be called anytime an error occurs.
43+
*/
44+
abstract error(callback: Function): Channel;
4045
}

src/channel/null-channel.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ export class NullChannel extends Channel {
3232
return this;
3333
}
3434

35+
/**
36+
* Register a callback to be called anytime an error occurs.
37+
*/
38+
error(callback: Function): NullChannel {
39+
return this;
40+
}
41+
3542
/**
3643
* Bind a channel to an event.
3744
*/

src/channel/pusher-channel.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { EventFormatter } from './../util';
1+
import { EventFormatter } from '../util';
22
import { Channel } from './channel';
33

44
/**
@@ -76,6 +76,17 @@ export class PusherChannel extends Channel {
7676
return this;
7777
}
7878

79+
/**
80+
* Register a callback to be called anytime a subscription error occurs.
81+
*/
82+
error(callback: Function): PusherChannel {
83+
this.on('pusher:subscription_error', (status) => {
84+
callback(status);
85+
});
86+
87+
return this;
88+
}
89+
7990
/**
8091
* Bind a channel to an event.
8192
*/

src/channel/socketio-channel.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { EventFormatter } from './../util';
1+
import { EventFormatter } from '../util';
22
import { Channel } from './channel';
33

44
/**
@@ -87,6 +87,13 @@ export class SocketIoChannel extends Channel {
8787
return this;
8888
}
8989

90+
/**
91+
* Register a callback to be called anytime an error occurs.
92+
*/
93+
error(callback: Function): SocketIoChannel {
94+
return this;
95+
}
96+
9097
/**
9198
* Bind the channel's socket to an event and store the callback.
9299
*/

0 commit comments

Comments
 (0)