mcavage/node-restify — pull request #116 by domenic (2012-04-06 15:08:52+00:00)
Title: Making error objects a bit more user-friendly.

* Don't use getters for `code`/`restCode`/`statusCode`/`httpCode`. Fixes GH-112.
* Put `name` properties on the prototype, to better match native error types and the patterns expected of them.
* Set `displayName` on the constructors, since otherwise they are anonymous functions in any stack traces.

---

The only missing thing that makes these errors behave unlike real errors is that, e.g.,

```js
NotFoundError.name === ""
```

This causes problems for some libraries like Chai, which assume the existence of a `name` property.

Unfortunately the only way to fix this would be `eval`, since `name` is non-writable and non-configurable. Something like:

``` js
eval('module.exports[name] = function ' + name + '(message, body, caller) {
HttpError.call(this,
code,
message,
body || null,
caller || this.constructor);
};');
```

If you think that's worth the cost let me know and I can add it to this pull request. I'm on the fence personally.