1 | 'use strict'
|
2 |
|
3 | const path = require('path')
|
4 | const glob = require('glob')
|
5 | const logger = require('./lib/logger')
|
6 | const actionFiles = glob.sync('./lib/actions/*.js', {cwd: __dirname, strict: true})
|
7 |
|
8 | actionFiles.forEach((actionFile) => {
|
9 | module.exports[path.basename(actionFile).split('.')[0].split('Action')[0]] = require(actionFile)
|
10 | })
|
11 |
|
12 | function 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 |
|
18 | process.on('unhandledRejection', function (err) {
|
19 | formatException(err)
|
20 | process.exit(1)
|
21 | })
|
22 |
|
23 | process.on('uncaughtException', function (err) {
|
24 | formatException(err)
|
25 | process.exit(1)
|
26 | })
|