Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement error handling #284

Merged
merged 2 commits into from
Jul 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/channel/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,14 @@ export abstract class Channel {
abstract stopListening(event: string): Channel;

/**
* Stop listening for a whispser event on the channel instance.
* Stop listening for a whisper event on the channel instance.
*/
stopListeningForWhisper(event: string): Channel {
return this.stopListening('.client-' + event);
}

/**
* Register a callback to be called anytime an error occurs.
*/
abstract error(callback: Function): Channel;
}
7 changes: 7 additions & 0 deletions src/channel/null-channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ export class NullChannel extends Channel {
return this;
}

/**
* Register a callback to be called anytime an error occurs.
*/
error(callback: Function): NullChannel {
return this;
}

/**
* Bind a channel to an event.
*/
Expand Down
13 changes: 12 additions & 1 deletion src/channel/pusher-channel.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EventFormatter } from './../util';
import { EventFormatter } from '../util';
import { Channel } from './channel';

/**
Expand Down Expand Up @@ -76,6 +76,17 @@ export class PusherChannel extends Channel {
return this;
}

/**
* Register a callback to be called anytime a subscription error occurs.
*/
error(callback: Function): PusherChannel {
this.on('pusher:subscription_error', (status) => {
callback(status);
});

return this;
}

/**
* Bind a channel to an event.
*/
Expand Down
9 changes: 8 additions & 1 deletion src/channel/socketio-channel.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EventFormatter } from './../util';
import { EventFormatter } from '../util';
import { Channel } from './channel';

/**
Expand Down Expand Up @@ -87,6 +87,13 @@ export class SocketIoChannel extends Channel {
return this;
}

/**
* Register a callback to be called anytime an error occurs.
*/
error(callback: Function): SocketIoChannel {
return this;
}

/**
* Bind the channel's socket to an event and store the callback.
*/
Expand Down