fix(jobs): Add Error Message to JobStatus Failure (#6954)

This commit is contained in:
Diamond Lewis
2020-10-20 16:55:24 -05:00
committed by GitHub
parent 135569cd2b
commit 72428dce0f
2 changed files with 24 additions and 11 deletions

View File

@@ -1652,6 +1652,16 @@ describe('Cloud Code', () => {
); );
}); });
it('should set the failure message on the job error', async () => {
Parse.Cloud.job('myJobError', () => {
throw new Parse.Error(101, 'Something went wrong');
});
const job = await Parse.Cloud.startJob('myJobError');
const jobStatus = await Parse.Cloud.getJobStatus(job);
expect(jobStatus.get('message')).toEqual('Something went wrong');
expect(jobStatus.get('status')).toEqual('failed');
});
function getJobStatus(jobId) { function getJobStatus(jobId) {
const q = new Parse.Query('_JobStatus'); const q = new Parse.Query('_JobStatus');
return q.get(jobId, { useMasterKey: true }); return q.get(jobId, { useMasterKey: true });

View File

@@ -128,6 +128,9 @@ export function jobStatusHandler(config) {
if (message && typeof message === 'string') { if (message && typeof message === 'string') {
update.message = message; update.message = message;
} }
if (message instanceof Error && typeof message.message === 'string') {
update.message = message.message;
}
return handler.update({ objectId }, update); return handler.update({ objectId }, update);
}; };