Skip to content

Commit

Permalink
feat: Standarize error handling for subscription limits (#14)
Browse files Browse the repository at this point in the history
* Standarize error handling for subscription limits

* address review
  • Loading branch information
yodaiken authored and jquense committed Apr 19, 2018
1 parent 4a73d01 commit a07172b
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions src/AuthorizedSocketConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,24 +110,22 @@ export default class AuthorizedSocketConnection<TContext, TCredentials> {
{ id, query, variables }: Subscription,
cb?: Function,
) => {
if (
this.config.maxSubscriptionsPerConnection != null &&
this.subscriptions.size >= this.config.maxSubscriptionsPerConnection
) {
this.log('error', 'Max Subscription limit reached', {
maxSubscriptionsPerConnection: this.config
.maxSubscriptionsPerConnection,
});
this.emitError({
code: 'subscribe_failed.subscription_limit',
});
acknowledge(cb);
this.config.socket.disconnect();
return;
}

let result;
try {
if (
this.config.maxSubscriptionsPerConnection != null &&
this.subscriptions.size >= this.config.maxSubscriptionsPerConnection
) {
this.log('debug', 'Max Subscription limit reached', {
maxSubscriptionsPerConnection: this.config
.maxSubscriptionsPerConnection,
});
this.emitError({
code: 'subscribe_failed.subscription_limit',
});
return;
}

if (this.subscriptions.has(id)) {
this.log('debug', 'Duplicate subscription attempted', { id });

Expand Down

0 comments on commit a07172b

Please sign in to comment.