Skip to content

Commit 89deb5b

Browse files
committed
Refactor error handling
1 parent 26fbcf3 commit 89deb5b

8 files changed

+30
-30
lines changed

src/channel/channel.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,9 @@ export abstract class Channel {
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/null-presence-channel.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,6 @@ export class NullPresenceChannel extends NullChannel implements PresenceChannel
1212
return this;
1313
}
1414

15-
/**
16-
* Register a callback to be called anytime an error occurs.
17-
*/
18-
error(callback: Function): NullPresenceChannel {
19-
return this;
20-
}
21-
2215
/**
2316
* Listen for someone joining the channel.
2417
*/

src/channel/presence-channel.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@ export interface PresenceChannel {
77
*/
88
here(callback: Function): PresenceChannel;
99

10-
/**
11-
* Register a callback to be called anytime an error occurs.
12-
*/
13-
error(callback: Function): PresenceChannel;
14-
1510
/**
1611
* Listen for someone joining the channel.
1712
*/

src/channel/pusher-channel.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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/pusher-presence-channel.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,6 @@ export class PusherPresenceChannel extends PusherChannel implements PresenceChan
1616
return this;
1717
}
1818

19-
/**
20-
* Register a callback to be called anytime a subscription error occurs.
21-
*/
22-
error(callback: Function): PusherPresenceChannel {
23-
this.on('pusher:subscription_error', (status) => {
24-
callback(status);
25-
});
26-
27-
return this;
28-
}
29-
3019
/**
3120
* Listen for someone joining the channel.
3221
*/

src/channel/socketio-channel.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
*/

src/channel/socketio-presence-channel.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,6 @@ export class SocketIoPresenceChannel extends SocketIoPrivateChannel implements P
1616
return this;
1717
}
1818

19-
/**
20-
* Register a callback to be called anytime an error occurs.
21-
*/
22-
error(callback: Function): SocketIoPresenceChannel {
23-
return this;
24-
}
25-
2619
/**
2720
* Listen for someone joining the channel.
2821
*/

0 commit comments

Comments
 (0)