From a628aa719f9bafd11bdaf527ee2ec2edf1917f0e Mon Sep 17 00:00:00 2001 From: luin Date: Wed, 31 May 2017 13:14:21 +0800 Subject: [PATCH] fix: show error name the error stack for Node.js 8 --- lib/reply_error.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/reply_error.js b/lib/reply_error.js index b72795f6..42a72baf 100644 --- a/lib/reply_error.js +++ b/lib/reply_error.js @@ -1,9 +1,16 @@ 'use strict'; -module.exports = function ReplyError(message) { - Error.captureStackTrace(this, this.constructor); +var util = require('util'); + +function ReplyError(message) { this.name = this.constructor.name; - this.message = message; + this.message = message || ''; + + if (Error.captureStackTrace) { + Error.captureStackTrace(this, this.constructor); + } }; -require('util').inherits(module.exports, Error); +util.inherits(ReplyError, Error); + +module.exports = ReplyError;