Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwilson committed Feb 8, 2018
1 parent 2fbe400 commit 43c93fd
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ function createClientErrorConstructor (HttpError, name, code) {
}

inherits(ClientError, HttpError)
setName(ClientError, className)

ClientError.prototype.status = code
ClientError.prototype.statusCode = code
Expand Down Expand Up @@ -209,6 +210,7 @@ function createServerErrorConstructor (HttpError, name, code) {
}

inherits(ServerError, HttpError)
setName(ServerError, className)

ServerError.prototype.status = code
ServerError.prototype.statusCode = code
Expand Down Expand Up @@ -248,6 +250,21 @@ function populateConstructorExports (exports, codes, HttpError) {
'"I\'mateapot"; use "ImATeapot" instead')
}

/**
* Set the name property on an object where it
* may not be configurable.
* @private
*/

function setName (obj, val) {
var desc = Object.getOwnPropertyDescriptor(obj, 'name')

if (desc.configurable) {
desc.value = val
Object.defineProperty(obj, 'name', desc)
}
}

/**
* Convert a string of words to a JavaScript identifier.
* @private
Expand Down

0 comments on commit 43c93fd

Please sign in to comment.