Skip to content

Commit

Permalink
Revert "fix: allow Parse.Cloud.beforeSubscribe rejections to be cau…
Browse files Browse the repository at this point in the history
…ght by query.subscribe"

This reverts commit 3073b77.
  • Loading branch information
dblythy committed Jun 5, 2022
1 parent 3073b77 commit bc0a576
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 48 deletions.
27 changes: 0 additions & 27 deletions integration/test/ParseLiveQueryTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,31 +256,4 @@ describe('Parse LiveQuery', () => {
object.set({ foo: 'bar' });
await object.save();
});

it('live query can handle beforeConnect and beforeSubscribe errors', async () => {
const client = new Parse.LiveQueryClient({
applicationId: 'integration',
serverURL: 'ws://localhost:1337',
javascriptKey: null,
masterKey: null,
sessionToken: null,
installationId: null,
});
client.open();
const query = new Parse.Query('TestError');
let subscription = client.subscribe(query);
await expectAsync(subscription.subscribePromise).toBeRejectedWith(
new Parse.Error(141, 'not allowed to subscribe')
);
client.close();
await reconfigureServer({
cloud: `${__dirname}/cloud/before_connect.js`,
});
client.open();
subscription = client.subscribe(query);
await expectAsync(subscription.subscribePromise).toBeRejectedWith(
new Parse.Error(141, 'not allowed to connect')
);
client.close();
});
});
3 changes: 0 additions & 3 deletions integration/test/cloud/before_connect.js

This file was deleted.

4 changes: 0 additions & 4 deletions integration/test/cloud/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,3 @@ Parse.Cloud.job('CloudJob2', function () {
Parse.Cloud.job('CloudJobFailing', function () {
throw 'cloud job failed';
});

Parse.Cloud.beforeSubscribe('TestError', () => {
throw 'not allowed to subscribe';
});
16 changes: 2 additions & 14 deletions src/LiveQueryClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import EventEmitter from './EventEmitter';
import ParseObject from './ParseObject';
import LiveQuerySubscription from './LiveQuerySubscription';
import { resolvingPromise } from './promiseUtils';
import ParseError from './ParseError';

// The LiveQuery client inner state
const CLIENT_STATE = {
Expand Down Expand Up @@ -219,10 +218,6 @@ class LiveQueryClient extends EventEmitter {
this.subscriptions.set(this.requestId, subscription);
this.requestId += 1;
this.connectPromise.then(() => {
if (this.connectError) {
subscription.subscribePromise.reject(this.connectError);
return;
}
this.socket.send(JSON.stringify(subscribeRequest));
});

Expand Down Expand Up @@ -387,16 +382,10 @@ class LiveQueryClient extends EventEmitter {
setTimeout(() => subscription.emit(SUBSCRIPTION_EMMITER_TYPES.OPEN, response), 200);
}
break;
case OP_EVENTS.ERROR: {
const parseError = new ParseError(data.code, data.error);
if (!this.id) {
this.connectError = parseError;
this.connectPromise.resolve();
this.state = CLIENT_STATE.DISCONNECTED;
}
case OP_EVENTS.ERROR:
if (data.requestId) {
if (subscription) {
subscription.subscribePromise.reject(parseError);
subscription.subscribePromise.resolve();
setTimeout(() => subscription.emit(SUBSCRIPTION_EMMITER_TYPES.ERROR, data.error), 200);
}
} else {
Expand All @@ -409,7 +398,6 @@ class LiveQueryClient extends EventEmitter {
this._handleReconnect();
}
break;
}
case OP_EVENTS.UNSUBSCRIBED:
// We have already deleted subscription in unsubscribe(), do nothing here
break;
Expand Down

0 comments on commit bc0a576

Please sign in to comment.