NodeJS Mongoose Schema 'save' function error handling? NodeJS Mongoose Schema 'save' function error handling? mongoose mongoose

NodeJS Mongoose Schema 'save' function error handling?


From a quick glance, it looks like you are using express. When an object or array is passed to res.send() (like in the case an error occurs), it defaults to using JSON.stringify on the object/array and sets the content-type to application/json. (Ref: http://expressjs.com/4x/api.html#res.send). The message property of an Error object is not serialized when it is passed through JSON.stringify because it is defined with enumerable being false.

Ex.

 $ node > var err = new Error('This is a test') undefined > console.log(JSON.stringify(err)) {} undefined

Is it not possible to stringify an Error using JSON.stringify? has some examples of how to make sure the message property (and others if that is what you would like) are included.