fix: Throwing error in Cloud Code Triggers afterLogin, afterLogout crashes server (#8280)

BREAKING CHANGE: Throwing an error in Cloud Code Triggers `afterLogin`, `afterLogout` returns a rejected promise; in previous releases it crashed the server if you did not handle the error on the Node.js process level; consider adapting your code if your app currently handles these errors on the Node.js process level with `process.on('unhandledRejection', ...)`
This commit is contained in:
dblythy
2022-11-11 08:00:40 +11:00
committed by GitHub
parent 9d3c1c6918
commit 130d29074e
2 changed files with 54 additions and 37 deletions

View File

@@ -3103,6 +3103,36 @@ describe('beforeLogin hook', () => {
done();
});
it('does not crash server when throwing in afterLogin hook', async () => {
const error = new Parse.Error(2000, 'afterLogin error');
const trigger = {
afterLogin() {
throw error;
},
};
const spy = spyOn(trigger, 'afterLogin').and.callThrough();
Parse.Cloud.afterLogin(trigger.afterLogin);
await Parse.User.signUp('user', 'pass');
const response = await Parse.User.logIn('user', 'pass').catch(e => e);
expect(spy).toHaveBeenCalled();
expect(response).toEqual(error);
});
it('does not crash server when throwing in afterLogout hook', async () => {
const error = new Parse.Error(2000, 'afterLogout error');
const trigger = {
afterLogout() {
throw error;
},
};
const spy = spyOn(trigger, 'afterLogout').and.callThrough();
Parse.Cloud.afterLogout(trigger.afterLogout);
await Parse.User.signUp('user', 'pass');
const response = await Parse.User.logOut().catch(e => e);
expect(spy).toHaveBeenCalled();
expect(response).toEqual(error);
});
it('should have expected data in request', async done => {
Parse.Cloud.beforeLogin(req => {
expect(req.object).toBeDefined();