1 | 'use strict';
|
2 |
|
3 | const debug = require('debug');
|
4 | const { autoExit } = require('./unref-timeout');
|
5 | const { red } = require('colors');
|
6 | const { FilterChain } = require('./error-processor');
|
7 |
|
8 | const filterChain = new FilterChain();
|
9 |
|
10 | const handler = function (err) {
|
11 |
|
12 | filterChain.process(err.message, err).then(processed => {
|
13 |
|
14 |
|
15 | if (debug.enabled('*') && err.stack) {
|
16 | console.error(err.stack);
|
17 | } else if (err.message) {
|
18 | console.error(red(err.message));
|
19 | } else {
|
20 | console.error(err);
|
21 | }
|
22 |
|
23 | autoExit();
|
24 | });
|
25 | };
|
26 |
|
27 | module.exports = handler;
|
28 |
|