Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}).catch(error => {
stdout.write(chalk.blue(error.stack))
logger.error('Database fails to initialize...', error)
process.exit(1)
})
...error,
code: error.code || errorCodes.SERVER.code,
status: error.status || errorCodes.SERVER.status,
message: error.message || error,
stack: ![400, 401, 403, 422].includes(error.status) ? stackTrace.parse(error) : false,
src: `${process.env.NODE_ENV}:err:middleware`
})
logger.error(errorRes.message, error, { ...errorRes, req: error.req, meta: error.meta })
res.status(errorRes.status).json(errorRes)
}
if (error.stack) {
stdout.write(chalk.red('--------------- ERROR STACK BEGIN --------------\n'))
stdout.write(`${new Date()} env:dev/regular error\n`)
stdout.write(chalk.blue(error.stack))
stdout.write(chalk.red('\n---------------- ERROR STACK END ---------------\n\n'))
}
}
}
} else {
const errorRes = new ErrorResponse({
...error,
code: error.code || errorCodes.SERVER.code,
status: error.status || errorCodes.SERVER.status,
message: error.message || error,
stack: ![400, 401, 403, 422].includes(error.status) ? stackTrace.parse(error) : false,
src: `${process.env.NODE_ENV}:err:middleware`
})
logger.error(errorRes.message, error, { ...errorRes, req: error.req, meta: error.meta })
res.status(errorRes.status).json(errorRes)
}
if (error.stack) {
stdout.write(chalk.red('--------------- ERROR STACK BEGIN --------------\n'))
stdout.write(`${new Date()} env:dev/regular error\n`)
stdout.write(chalk.blue(error.stack))
stdout.write(chalk.red('\n---------------- ERROR STACK END ---------------\n\n'))
}
}
}