LiveQueryEvent Error Logging Improvements (#6951)

* LiveQueryEvent Improvements

* Update ParseLiveQueryServer.js

* Update ParseLiveQueryServer.js

* More Tests

* Update ParseLiveQueryServer.js

* Pass thrown errors to subscription

* Update ParseLiveQueryServer.js

* Update ParseLiveQueryServer.js

* Remove ACL error
This commit is contained in:
dblythy
2020-10-22 08:50:21 +11:00
committed by GitHub
parent c647c5336e
commit ef2e54c39d
3 changed files with 67 additions and 9 deletions

View File

@@ -231,7 +231,6 @@ describe('ParseLiveQuery', function () {
object.set({ foo: 'bar' }); object.set({ foo: 'bar' });
await object.save(); await object.save();
}); });
it('can handle afterEvent throw', async done => { it('can handle afterEvent throw', async done => {
await reconfigureServer({ await reconfigureServer({
liveQuery: { liveQuery: {
@@ -245,6 +244,37 @@ describe('ParseLiveQuery', function () {
const object = new TestObject(); const object = new TestObject();
await object.save(); await object.save();
Parse.Cloud.afterLiveQueryEvent('TestObject', () => {
throw 'Throw error from LQ afterEvent.';
});
const query = new Parse.Query(TestObject);
query.equalTo('objectId', object.id);
const subscription = await query.subscribe();
subscription.on('update', () => {
fail('update should not have been called.');
});
subscription.on('error', e => {
expect(e).toBe('Throw error from LQ afterEvent.');
done();
});
object.set({ foo: 'bar' });
await object.save();
});
it('can handle afterEvent sendEvent to false', async done => {
await reconfigureServer({
liveQuery: {
classNames: ['TestObject'],
},
startLiveQueryServer: true,
verbose: false,
silent: true,
});
const object = new TestObject();
await object.save();
Parse.Cloud.afterLiveQueryEvent('TestObject', req => { Parse.Cloud.afterLiveQueryEvent('TestObject', req => {
const current = req.object; const current = req.object;
const original = req.original; const original = req.original;
@@ -254,7 +284,7 @@ describe('ParseLiveQuery', function () {
}, 2000); }, 2000);
if (current.get('foo') != original.get('foo')) { if (current.get('foo') != original.get('foo')) {
throw "Don't pass an update trigger, or message"; req.sendEvent = false;
} }
}); });

View File

@@ -182,11 +182,15 @@ class ParseLiveQueryServer {
clients: this.clients.size, clients: this.clients.size,
subscriptions: this.subscriptions.size, subscriptions: this.subscriptions.size,
useMasterKey: client.hasMasterKey, useMasterKey: client.hasMasterKey,
installationId: client.installationId installationId: client.installationId,
sendEvent: true,
}; };
return maybeRunAfterEventTrigger('afterEvent', className, res); return maybeRunAfterEventTrigger('afterEvent', className, res);
}) })
.then(() => { .then(() => {
if (!res.sendEvent) {
return;
}
if (res.object && typeof res.object.toJSON === 'function') { if (res.object && typeof res.object.toJSON === 'function') {
deletedParseObject = res.object.toJSON(); deletedParseObject = res.object.toJSON();
deletedParseObject.className = className; deletedParseObject.className = className;
@@ -194,7 +198,17 @@ class ParseLiveQueryServer {
client.pushDelete(requestId, deletedParseObject); client.pushDelete(requestId, deletedParseObject);
}) })
.catch(error => { .catch(error => {
logger.error('Matching ACL error : ', error); Client.pushError(
client.parseWebSocket,
error.code || 141,
error.message || error,
false,
requestId
);
logger.error(
`Failed running afterLiveQueryEvent on class ${className} for event ${res.event} with session ${res.sessionToken} with:\n Error: ` +
JSON.stringify(error)
);
}); });
} }
} }
@@ -297,7 +311,6 @@ class ParseLiveQueryServer {
isCurrentMatched, isCurrentMatched,
subscription.hash subscription.hash
); );
// Decide event type // Decide event type
let type; let type;
if (isOriginalMatched && isCurrentMatched) { if (isOriginalMatched && isCurrentMatched) {
@@ -322,12 +335,16 @@ class ParseLiveQueryServer {
clients: this.clients.size, clients: this.clients.size,
subscriptions: this.subscriptions.size, subscriptions: this.subscriptions.size,
useMasterKey: client.hasMasterKey, useMasterKey: client.hasMasterKey,
installationId: client.installationId installationId: client.installationId,
sendEvent: true,
}; };
return maybeRunAfterEventTrigger('afterEvent', className, res); return maybeRunAfterEventTrigger('afterEvent', className, res);
}) })
.then( .then(
() => { () => {
if (!res.sendEvent) {
return;
}
if (res.object && typeof res.object.toJSON === 'function') { if (res.object && typeof res.object.toJSON === 'function') {
currentParseObject = res.object.toJSON(); currentParseObject = res.object.toJSON();
currentParseObject.className = currentParseObject.className =
@@ -349,7 +366,17 @@ class ParseLiveQueryServer {
} }
}, },
error => { error => {
logger.error('Matching ACL error : ', error); Client.pushError(
client.parseWebSocket,
error.code || 141,
error.message || error,
false,
requestId
);
logger.error(
`Failed running afterLiveQueryEvent on class ${className} for event ${res.event} with session ${res.sessionToken} with:\n Error: ` +
JSON.stringify(error)
);
} }
); );
} }
@@ -658,7 +685,7 @@ class ParseLiveQueryServer {
} catch (error) { } catch (error) {
Client.pushError( Client.pushError(
parseWebsocket, parseWebsocket,
error.code || 101, error.code || 141,
error.message || error, error.message || error,
false false
); );
@@ -776,7 +803,7 @@ class ParseLiveQueryServer {
} catch (e) { } catch (e) {
Client.pushError( Client.pushError(
parseWebsocket, parseWebsocket,
e.code || 101, e.code || 141,
e.message || e, e.message || e,
false, false,
request.requestId request.requestId

View File

@@ -600,6 +600,7 @@ module.exports = ParseCloud;
* @property {Parse.Object} original If set, the object, as currently stored. * @property {Parse.Object} original If set, the object, as currently stored.
* @property {Integer} clients The number of clients connected. * @property {Integer} clients The number of clients connected.
* @property {Integer} subscriptions The number of subscriptions connected. * @property {Integer} subscriptions The number of subscriptions connected.
* @property {Boolean} sendEvent If the LiveQuery event should be sent to the client. Set to false to prevent LiveQuery from pushing to the client.
*/ */
/** /**