UNPKG

788 BJavaScriptView Raw
1'use strict'
2
3const path = require('path')
4const glob = require('glob')
5const logger = require('./lib/logger')
6const actionFiles = glob.sync('./lib/actions/*.js', {cwd: __dirname, strict: true})
7
8actionFiles.forEach((actionFile) => {
9 module.exports[path.basename(actionFile).split('.')[0].split('Action')[0]] = require(actionFile)
10})
11
12function formatException (err) {
13 if (err.code && err.message) return logger.error(`${err.message} (${err.code})`)
14 if (err.stack) err.stack = err.stack.split('\n').slice(0, 4).join('\n')
15 logger.error(process.env.LOG_LEVEL !== 'debug' ? err.message : err)
16}
17
18process.on('unhandledRejection', function (err) {
19 formatException(err)
20 process.exit(1)
21})
22
23process.on('uncaughtException', function (err) {
24 formatException(err)
25 process.exit(1)
26})