Skip to content

Commit 6081d2e

Browse files
committed
fixes senecajs#711
1 parent a9a4b47 commit 6081d2e

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

lib/outward.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ function outward_res_object(ctxt, data) {
107107
!!res.force$
108108
)
109109

110+
// Responding with an Error as data is not allowed.
111+
// https://github.com/senecajs/seneca/issues/711
112+
if(data.out instanceof Error) {
113+
not_object = true
114+
}
115+
110116
var not_legacy = !(
111117
msg.cmd === 'generate_id' ||
112118
msg.note === true ||

test/error.test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ var arrayify = Function.prototype.apply.bind(Array.prototype.slice)
2121
var make_test_transport = TransportStubs.make_test_transport
2222

2323
describe('error', function() {
24+
it('response_is_error', response_is_error)
2425
it('action_callback', action_callback)
2526
it('plugin_load', plugin_load)
2627

@@ -45,6 +46,28 @@ describe('error', function() {
4546

4647
it('legacy_fail', legacy_fail)
4748

49+
50+
function response_is_error(fin) {
51+
var si = Seneca({ log: 'silent' })
52+
53+
si.add('a:1', function(msg, reply) {
54+
var foo = new Error('foo')
55+
foo.a = 1
56+
reply(null, foo)
57+
})
58+
59+
si.error(function(err){
60+
expect(err.code).equal('result_not_objarr')
61+
fin()
62+
})
63+
64+
si.act('a:1', function(err, out) {
65+
expect(out).not.exist()
66+
expect(err.code).equal('result_not_objarr')
67+
})
68+
}
69+
70+
4871
function action_callback(fin) {
4972
var si = Seneca({ log: 'silent' })
5073

0 commit comments

Comments
 (0)