-
-
Notifications
You must be signed in to change notification settings - Fork 70
/
error-propagation.js
77 lines (74 loc) 路 1.34 KB
/
error-propagation.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
'use strict'
const Hemera = require('./../../packages/hemera')
const nats = require('nats').connect()
const hemera = new Hemera(nats, {
logLevel: 'info'
})
const UnauthorizedError = Hemera.createError('Unauthorized')
hemera.ready(() => {
hemera.add(
{
topic: 'a',
cmd: 'a'
},
function(resp, cb) {
this.act(
{
topic: 'b',
cmd: 'b'
},
function(err, resp) {
this.act(
{
topic: 'c',
cmd: 'c'
},
function(err, resp) {
cb(err, resp)
}
)
}
)
}
)
hemera.add(
{
topic: 'b',
cmd: 'b'
},
(resp, cb) => {
const a = new UnauthorizedError('test')
a.test = 444
cb(a)
}
)
hemera.add(
{
topic: 'c',
cmd: 'c'
},
function(resp, cb) {
this.act(
{
topic: 'b',
cmd: 'b'
},
function(err, resp) {
cb(err, resp)
}
)
}
)
hemera.act(
{
topic: 'a',
cmd: 'a'
},
function(err, resp) {
this.log.info('Error name: %s', err.name)
this.log.info('Error message: %s', err.message)
this.log.info('Custom error data: test=%s', err.test)
this.log.info(err.hops, 'network hops')
}
)
})