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

Catch error w/ callback, dependency update, ... #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"dist"
],
"dependencies": {
"rethinkdb-websocket-client": "^0.4.7"
"rethinkdb-websocket-client": "^0.5.1"
},
"devDependencies": {
"babel": "^5.5.6",
Expand Down
7 changes: 4 additions & 3 deletions src/Session.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ export const MetaSession = RethinkdbWebsocketClient => {
this._subscriptionManager = new SubscriptionManager(runQueryFn);
}

connect({host, port, path, wsProtocols, secure, db, simulatedLatencyMs, autoReconnectDelayMs}) {
connect({host, port, path, wsProtocols, secure, db, simulatedLatencyMs, autoReconnectDelayMs, onConnectionErrorCallback}) {
ensure(!this._connPromise, 'Session.connect() called when connected');
const _onConnectionErrorCallback = onConnectionErrorCallback ? onConnectionErrorCallback : e => console.log(e);
const connectAfterDelay = delayMs => {
const options = {host, port, path, wsProtocols, secure, db, simulatedLatencyMs};
this._connPromise = new Promise((resolve, reject) => {
Expand All @@ -48,15 +49,15 @@ export const MetaSession = RethinkdbWebsocketClient => {
this._subscriptionManager.handleDisconnect();
// Don't trigger on client initiated Session.close()
if (this._connPromise) {
console.warn('RethinkDB WebSocket connection failure.',
console.log('RethinkDB WebSocket connection failure.',
`Reconnecting in ${autoReconnectDelayMs}ms`);
connectAfterDelay(autoReconnectDelayMs);
}
};
if (autoReconnectDelayMs !== undefined) {
this._connPromise.then(conn => conn.on('close', onClose), onClose);
}
this._connPromise.then(() => this._subscriptionManager.handleConnect());
this._connPromise.then(() => this._subscriptionManager.handleConnect()).catch(_onConnectionErrorCallback);
};
connectAfterDelay(0);
}
Expand Down