Skip to content

Commit 91b516a

Browse files
committed
fix (invoke-handler) error with string code causes exception on server
1 parent 501e09a commit 91b516a

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

lib/server-code/runners/tasks/util/result-wrapper.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,16 @@ exports.invocationResult = function(err, args) {
2020
};
2121
};
2222

23-
2423
/**
2524
* @param {?Error|ExceptionWrapper|String} err
2625
* @returns {Object}
2726
*/
2827
exports.exception = function(err) {
28+
const errCode = typeof err.code === 'number' ? err.code : 0;
29+
2930
return {
3031
___jsonclass : err.___jsonclass || 'com.backendless.commons.exception.ExceptionWrapper',
31-
code : err.code || 0,
32+
code : errCode,
3233
exceptionClass : err.exceptionClass || 'java.lang.Exception',
3334
exceptionMessage: err.exceptionMessage || err.message || err
3435
};

test/invoke-handler-task.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,21 @@ describe('[invoke-handler] task executor', function() {
141141
});
142142
});
143143

144+
it('and escape string error code', function() {
145+
function handler() {
146+
const err = new Error('StreamError');
147+
err.code = 'ENOTFOUND';
148+
149+
throw err;
150+
}
151+
152+
return invokeAndParse(createTask(BEFORE_CREATE), modelStub(handler)).then(res => {
153+
should.exist(res.exception);
154+
res.exception.code.should.equal(0);
155+
res.exception.exceptionMessage.should.equal('StreamError');
156+
});
157+
});
158+
144159
it('async errors raised in the event handler behind the promise', function() {
145160
function handler() {
146161
process.nextTick(() => {

0 commit comments

Comments
 (0)