diff --git a/package-lock.json b/package-lock.json index d59d30e47cc..3cb400b765a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4413,15 +4413,6 @@ "is-arrayish": "0.2.1" } }, - "errorhandler": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/errorhandler/-/errorhandler-1.5.0.tgz", - "integrity": "sha1-6rpkyl1UKjEayUX1gt78M2Fl2fQ=", - "requires": { - "accepts": "1.3.4", - "escape-html": "1.0.3" - } - }, "es-abstract": { "version": "1.9.0", "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.9.0.tgz", diff --git a/package.json b/package.json index d2a2a1498fa..4c91aca62e7 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,6 @@ "emmet-codemirror": "^1.2.5", "enzyme": "^3.2.0", "enzyme-adapter-react-15": "^1.0.5", - "errorhandler": "^1.4.2", "es6-map": "~0.1.1", "express": "^4.13.3", "express-flash": "~0.0.2", diff --git a/server/middlewares/error-handlers.js b/server/middlewares/error-handlers.js index 5e11a76dfa3..b2c0029341d 100644 --- a/server/middlewares/error-handlers.js +++ b/server/middlewares/error-handlers.js @@ -1,11 +1,47 @@ -import errorHandler from 'errorhandler'; +import { inspect } from 'util'; +import _ from 'lodash/fp'; import accepts from 'accepts'; import { unwrapHandledError } from '../utils/create-handled-error.js'; -export default function prodErrorHandler() { - if (process.env.NODE_ENV === 'development') { - return errorHandler({ log: true }); +const isDev = process.env.NODE_ENV !== 'production'; + +const toString = Object.prototype.toString; +// is full error or just trace +// _.toString(new Error('foo')) => "Error: foo +// Object.prototype.toString.call(new Error('foo')) => "[object Error]" +const isInspect = val => !val.stack && _.toString(val) === toString.call(val); +const stringifyErr = val => { + if (val.stack) { + return String(val.stack); } + + const str = String(val); + + return isInspect(val) ? + inspect(val) : + str; +}; + +const createStackHtml = _.flow( + _.cond([ + [isInspect, err => [err]], + // may be stack or just err.msg + [_.stubTrue, _.flow(stringifyErr, _.split('\n'), _.tail) ] + ]), + _.map(_.escape), + _.map(line => `