{"action":"created","issue":{"url":"https://api.github.com/repos/shutterstock/node-common-errors/issues/17","labels_url":"https://api.github.com/repos/shutterstock/node-common-errors/issues/17/labels{/name}","comments_url":"https://api.github.com/repos/shutterstock/node-common-errors/issues/17/comments","events_url":"https://api.github.com/repos/shutterstock/node-common-errors/issues/17/events","html_url":"https://github.com/shutterstock/node-common-errors/issues/17","id":112089618,"number":17,"title":"Append extra data to errors","user":{"login":"thefabulousdev","id":12737509,"avatar_url":"https://avatars.githubusercontent.com/u/12737509?v=3","gravatar_id":"","url":"https://api.github.com/users/thefabulousdev","html_url":"https://github.com/thefabulousdev","followers_url":"https://api.github.com/users/thefabulousdev/followers","following_url":"https://api.github.com/users/thefabulousdev/following{/other_user}","gists_url":"https://api.github.com/users/thefabulousdev/gists{/gist_id}","starred_url":"https://api.github.com/users/thefabulousdev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thefabulousdev/subscriptions","organizations_url":"https://api.github.com/users/thefabulousdev/orgs","repos_url":"https://api.github.com/users/thefabulousdev/repos","events_url":"https://api.github.com/users/thefabulousdev/events{/privacy}","received_events_url":"https://api.github.com/users/thefabulousdev/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-10-19T07:48:45Z","updated_at":"2015-10-19T16:37:34Z","closed_at":null,"body":"Is it possible to append extra data to the errors? My particular interest is on the custom ones.\r\n\r\ne,g,\r\n\r\n```js\r\nvar TokenModelNotFoundError = helpers.generateClass('TokenModelNotFoundError', {\r\n    extends: errors.NotFoundError,\r\n    args: ['modelName','tokenName'],\r\n    generateMessage: function(){\r\n        return sprintf('The %s model from the given %s token was not found',this.modelName,this.tokenName);\r\n    },\r\n    someExtraData : {\r\n        journey : function(){\r\n            // Do something, perhaps with the arguments given\r\n            return someObject;\r\n        }\r\n    }\r\n});\r\n```\r\nand have it on the generated JSON\r\n```js\r\n{\r\n    // ...\r\n    someExtraData : {\r\n        journey : { // The generated object }\r\n    }\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/shutterstock/node-common-errors/issues/comments/149274864","html_url":"https://github.com/shutterstock/node-common-errors/issues/17#issuecomment-149274864","issue_url":"https://api.github.com/repos/shutterstock/node-common-errors/issues/17","id":149274864,"user":{"login":"dfenster","id":176906,"avatar_url":"https://avatars.githubusercontent.com/u/176906?v=3","gravatar_id":"","url":"https://api.github.com/users/dfenster","html_url":"https://github.com/dfenster","followers_url":"https://api.github.com/users/dfenster/followers","following_url":"https://api.github.com/users/dfenster/following{/other_user}","gists_url":"https://api.github.com/users/dfenster/gists{/gist_id}","starred_url":"https://api.github.com/users/dfenster/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dfenster/subscriptions","organizations_url":"https://api.github.com/users/dfenster/orgs","repos_url":"https://api.github.com/users/dfenster/repos","events_url":"https://api.github.com/users/dfenster/events{/privacy}","received_events_url":"https://api.github.com/users/dfenster/received_events","type":"User","site_admin":false},"created_at":"2015-10-19T16:37:34Z","updated_at":"2015-10-19T16:37:34Z","body":"One thing you could do is add your own \"toJSON\" method on the class that you get as a result of the generateClass method. Then, when you call JSON.stringify, it will use that method to know what the output should be.\r\n\r\nDid you have a different idea, or a suggestion on what you would like the library to do? Is there some value here that I can add that would benefit you and others?"}}