Allow custom error codes with response.error from Cloud Code functions and before/after hooks (#1955)
This commit is contained in:
committed by
Florent Vilmart
parent
103839ce60
commit
c6c9c97b54
@@ -64,6 +64,23 @@ describe('Cloud Code', () => {
|
||||
})
|
||||
});
|
||||
|
||||
it('beforeSave rejection with custom error code', function(done) {
|
||||
Parse.Cloud.beforeSave('BeforeSaveFailWithErrorCode', function (req, res) {
|
||||
res.error(999, 'Nope');
|
||||
});
|
||||
|
||||
var obj = new Parse.Object('BeforeSaveFailWithErrorCode');
|
||||
obj.set('foo', 'bar');
|
||||
obj.save().then(function() {
|
||||
fail('Should not have been able to save BeforeSaveFailWithErrorCode class.');
|
||||
done();
|
||||
}, function(error) {
|
||||
expect(error.code).toEqual(999);
|
||||
expect(error.message).toEqual('Nope');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('basic beforeSave rejection via promise', function(done) {
|
||||
Parse.Cloud.beforeSave('BeforeSaveFailWithPromise', function (req, res) {
|
||||
var query = new Parse.Query('Yolo');
|
||||
|
||||
@@ -724,6 +724,36 @@ describe('miscellaneous', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('test cloud function error handling with custom error code', (done) => {
|
||||
// Register a function which will fail
|
||||
Parse.Cloud.define('willFail', (req, res) => {
|
||||
res.error(999, 'noway');
|
||||
});
|
||||
Parse.Cloud.run('willFail').then((s) => {
|
||||
fail('Should not have succeeded.');
|
||||
done();
|
||||
}, (e) => {
|
||||
expect(e.code).toEqual(999);
|
||||
expect(e.message).toEqual('noway');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('test cloud function error handling with standard error code', (done) => {
|
||||
// Register a function which will fail
|
||||
Parse.Cloud.define('willFail', (req, res) => {
|
||||
res.error('noway');
|
||||
});
|
||||
Parse.Cloud.run('willFail').then((s) => {
|
||||
fail('Should not have succeeded.');
|
||||
done();
|
||||
}, (e) => {
|
||||
expect(e.code).toEqual(Parse.Error.SCRIPT_FAILED);
|
||||
expect(e.message).toEqual('noway');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('test beforeSave/afterSave get installationId', function(done) {
|
||||
let triggerTime = 0;
|
||||
Parse.Cloud.beforeSave('GameScore', function(req, res) {
|
||||
|
||||
Reference in New Issue
Block a user