From ad7357e139ed1a8a8e4f868d12ff82feca5c4a8b Mon Sep 17 00:00:00 2001 From: Hans Date: Fri, 29 Jul 2022 14:53:48 +0800 Subject: [PATCH] feat(Server): pretty custom error inspect --- packages/server/js/errors.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/server/js/errors.js b/packages/server/js/errors.js index 761dc65..5761843 100644 --- a/packages/server/js/errors.js +++ b/packages/server/js/errors.js @@ -1,3 +1,5 @@ +const util = require('util') + module.exports = class ServerError extends Error { constructor (options = {}) { super() @@ -21,4 +23,8 @@ module.exports = class ServerError extends Error { return `ServerError: ${this.code}: ${this.message}` } } + + [util.inspect.custom] () { + return `[${this.code}] ${this.message || (this.originError && this.originError.message) || 'Unknown Error'}` + } }