diff --git a/package.json b/package.json index 34239b9..11ce229 100644 --- a/package.json +++ b/package.json @@ -64,6 +64,7 @@ "delegates": "^1.0.0", "koa-compose": "^4.1.0", "only": "^0.0.2", + "serialize-error": "^3.0.0", "shortid": "^2.2.12" } } diff --git a/src/index.js b/src/index.js index 21918a3..f7a9a93 100644 --- a/src/index.js +++ b/src/index.js @@ -5,6 +5,7 @@ import util from "util"; import compose from "koa-compose"; import Debugger from "debug"; import only from "only"; +import serializeError from "serialize-error"; import Session from "./session"; import Context from "./context"; @@ -172,10 +173,7 @@ export default class Application extends Emitter { if (this.silent) return; - const msg = err.stack || err.toString(); - console.error(); - console.error(msg.replace(/^/gm, " ")); - console.error(); + console.error(serializeError(err)); } /** diff --git a/yarn.lock b/yarn.lock index 1a64147..295ec07 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6136,6 +6136,10 @@ semver@5.5.0: version "5.5.0" resolved "https://registry.yarnpkg.com/semver/-/semver-5.5.0.tgz#dc4bbc7a6ca9d916dee5d43516f0092b58f7b8ab" +serialize-error@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/serialize-error/-/serialize-error-3.0.0.tgz#80100282b09be33c611536f50033481cb9cc87cf" + set-blocking@^2.0.0, set-blocking@~2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/set-blocking/-/set-blocking-2.0.0.tgz#045f9782d011ae9a6803ddd382b24392b3d890f7"