I face an interesting challenge in my error handling with mongoose and express. when I return the mongoose error(casterror or validation error) I can't see 'name' property in postman. even when I console.log(err) there is no name property on error object. but when I write: console.log(err.name) it returns it correctly. also when i make copy object, I can't even log copy object name property:
const error = { ...err }; console.log(error.name) => return` undefined. after some searching, I found something name enumerable. and I understood when enumerable is false on the property I can't see that in console.log or in for loop and etc(like a stack of err). I try to change enumerable to true and I come to succeed on the stack and I can see that :
Object.defineProperty(err, 'stack', {
enumerable: true,
});
//now satck is sho in console.log(err);) but when I do it on name property there is no change and even worse. because now console.log(err.name) return undefined. I want to know what is the reason?