UNPKG

778 BJavaScriptView Raw
1'use strict';
2
3const debug = require('debug');
4const { autoExit } = require('./unref-timeout');
5const { red } = require('colors');
6const { FilterChain } = require('./error-processor');
7
8const filterChain = new FilterChain();
9
10const handler = function (err) {
11 // err may be null when fun local || fun build || fun install
12 filterChain.process(err.message, err).then(processed => {
13 // If the verbose option is true, in addition to the message,
14 // print the stack of the error.
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 // in order visitor request has been sent out
23 autoExit();
24 });
25};
26
27module.exports = handler;
28