Handle possible afterSave exception (#4293)
* capture and log exceptions caused by afterFind * Wording * Consolidated promise chaining * use logger instead of console
This commit is contained in:
committed by
Florent Vilmart
parent
c2fc0f556e
commit
87b79cedfa
@@ -1076,6 +1076,19 @@ describe('Cloud Code', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verifies that an afterSave hook throwing an exception
|
||||||
|
* will not prevent a successful save response from being returned
|
||||||
|
*/
|
||||||
|
it('should succeed on afterSave exception', (done) => {
|
||||||
|
Parse.Cloud.afterSave("AfterSaveTestClass", function () {
|
||||||
|
throw "Exception";
|
||||||
|
});
|
||||||
|
const AfterSaveTestClass = Parse.Object.extend('AfterSaveTestClass');
|
||||||
|
const obj = new AfterSaveTestClass();
|
||||||
|
obj.save().then(done, done.fail);
|
||||||
|
});
|
||||||
|
|
||||||
describe('cloud jobs', () => {
|
describe('cloud jobs', () => {
|
||||||
it('should define a job', (done) => {
|
it('should define a job', (done) => {
|
||||||
expect(() => {
|
expect(() => {
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ var triggers = require('./triggers');
|
|||||||
var ClientSDK = require('./ClientSDK');
|
var ClientSDK = require('./ClientSDK');
|
||||||
import RestQuery from './RestQuery';
|
import RestQuery from './RestQuery';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
import logger from './logger';
|
||||||
|
|
||||||
// query and data are both provided in REST API format. So data
|
// query and data are both provided in REST API format. So data
|
||||||
// types are encoded by plain old objects.
|
// types are encoded by plain old objects.
|
||||||
@@ -1121,7 +1122,10 @@ RestWrite.prototype.runAfterTrigger = function() {
|
|||||||
this.config.liveQueryController.onAfterSave(updatedObject.className, updatedObject, originalObject);
|
this.config.liveQueryController.onAfterSave(updatedObject.className, updatedObject, originalObject);
|
||||||
|
|
||||||
// Run afterSave trigger
|
// Run afterSave trigger
|
||||||
return triggers.maybeRunTrigger(triggers.Types.afterSave, this.auth, updatedObject, originalObject, this.config);
|
return triggers.maybeRunTrigger(triggers.Types.afterSave, this.auth, updatedObject, originalObject, this.config)
|
||||||
|
.catch(function(err) {
|
||||||
|
logger.warn('afterSave caught an error', err);
|
||||||
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
// A helper to figure out what location this operation happens at.
|
// A helper to figure out what location this operation happens at.
|
||||||
|
|||||||
Reference in New Issue
Block a user