forked from koajs/mount
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.js
More file actions
48 lines (37 loc) · 949 Bytes
/
errors.js
File metadata and controls
48 lines (37 loc) · 949 Bytes
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
/**
* This example illustrates how application
* errors propagate upstream for
* centralized logging etc.
*/
var mount = require('..');
var koa = require('koa');
var a = koa();
var b = koa();
var c = koa();
a.use(function *(next){
yield next;
});
b.use(function *(next){
yield next;
});
c.use(function *(next){
yield next;
throw new Error('tobi escaped!');
});
a.use(mount(b));
b.use(mount(c));
// suppress stderr output if you want
a.outputErrors = false;
// errors will propagate to the upstream app,
// however you can still use the "error" listener
// in subapps more specific behaviour, just keep
// in mind that it should be used in an unobtrusive way,
// since most decisions should be made by the parent app.
a.on('error', function(err, ctx){
console.log('%s %s: sending error "%s" to alert service',
ctx.method,
ctx.path,
err.message);
});
a.listen(3000);
console.log('listening on port 3000');