Skip to content

Commit cfb8734

Browse files
committed
Only accept strings as messages
1 parent f40dd20 commit cfb8734

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

spec/CloudCode.spec.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,7 +1080,8 @@ it('beforeSave should not affect fetched pointers', done => {
10801080

10811081
it('should set the message / success on the job', (done) => {
10821082
Parse.Cloud.job('myJob', (req, res) => {
1083-
res.message('hello').then(() => {
1083+
res.message('hello');
1084+
res.message().then(() => {
10841085
return getJobStatus(req.jobId);
10851086
}).then((jobStatus) => {
10861087
expect(jobStatus.get('message')).toEqual('hello');
@@ -1089,7 +1090,7 @@ it('beforeSave should not affect fetched pointers', done => {
10891090
return getJobStatus(req.jobId);
10901091
});
10911092
}).then((jobStatus) => {
1092-
expect(typeof jobStatus.get('message')).not.toBe('string');
1093+
expect(jobStatus.get('message')).toEqual('hello');
10931094
expect(jobStatus.get('status')).toEqual('succeeded');
10941095
done();
10951096
}).catch(err => {

src/StatusHandler.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ export function jobStatusHandler(config) {
6363
}
6464

6565
let setMessage = function(message) {
66+
if (!message || typeof message !== 'string') {
67+
return Promise.resolve();
68+
}
6669
return handler.update({ objectId }, { message });
6770
}
6871

@@ -74,9 +77,13 @@ export function jobStatusHandler(config) {
7477
return setFinalStatus('failed', message);
7578
}
7679

77-
let setFinalStatus = function(status, message = null) {
80+
let setFinalStatus = function(status, message = undefined) {
7881
let finishedAt = new Date();
79-
return handler.update({ objectId }, { status, message, finishedAt });
82+
let update = { status, finishedAt };
83+
if (message && typeof message === 'string') {
84+
update.message = message;
85+
}
86+
return handler.update({ objectId }, update);
8087
}
8188

8289
return Object.freeze({

0 commit comments

Comments
 (0)