Skip to content

Commit 6f10484

Browse files
committed
Set constructor name when possible
closes #12
1 parent 25166de commit 6f10484

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

HISTORY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
unreleased
22
==========
33

4+
* Set constructor name when possible
45
* deps: statuses@'>= 1.5.0 < 2'
56

67
2018-03-29 / 1.6.3

index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ function createClientErrorConstructor (HttpError, name, code) {
162162
}
163163

164164
inherits(ClientError, HttpError)
165+
nameFunc(ClientError, className)
165166

166167
ClientError.prototype.status = code
167168
ClientError.prototype.statusCode = code
@@ -209,6 +210,7 @@ function createServerErrorConstructor (HttpError, name, code) {
209210
}
210211

211212
inherits(ServerError, HttpError)
213+
nameFunc(ServerError, className)
212214

213215
ServerError.prototype.status = code
214216
ServerError.prototype.statusCode = code
@@ -217,6 +219,20 @@ function createServerErrorConstructor (HttpError, name, code) {
217219
return ServerError
218220
}
219221

222+
/**
223+
* Set the name of a function, if possible.
224+
* @private
225+
*/
226+
227+
function nameFunc (func, name) {
228+
var desc = Object.getOwnPropertyDescriptor(func, 'name')
229+
230+
if (desc.configurable) {
231+
desc.value = name
232+
Object.defineProperty(func, 'name', desc)
233+
}
234+
}
235+
220236
/**
221237
* Populate the exports object with constructors for every error class.
222238
* @private

0 commit comments

Comments
 (0)