complete-node-bootcamp
complete-node-bootcamp copied to clipboard
120 Handling Mongoose Validation Errors - overwhelmed with errors over object destructuring
Sometimes it's simpler to show in the snapshot than typing hundreds of words. The problem occurred over the code line: let error = { ...err }; Basically, I don't know the reason but if I send error.name to console I get undefined. The field doesn't exist after destructuring err.
One lesson before this one I had an issue with handleDuplicateFieldsDB function in which I had to use err.keyValue.name instead of using errmsg.match(RegEx...).

let error = {...err, message: err.message, name: err.name}; -- here is fix
Same thing for me. I really wonder what's causing the error but you can fix that using deep copy. Here is how you can do it : let error = JSON.parse(JSON.stringify(err));
the request is hanging when i change the env value to production can someone explain that to me why