Skip to content

Instantly share code, notes, and snippets.

@itayw
Created December 12, 2013 13:14
Show Gist options
  • Save itayw/7927759 to your computer and use it in GitHub Desktop.
Save itayw/7927759 to your computer and use it in GitHub Desktop.
Object.defineProperty(Error.prototype, 'toJSON', {
value: function () {
var alt = {};
Object.getOwnPropertyNames(this).forEach(function (key) {
alt[key] = this[key];
}, this);
return alt;
},
configurable: true
});
var error = new Error('testing');
error.detail = 'foo bar';
console.log(JSON.stringify(error));
// {"message":"testing","detail":"foo bar"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment