complete-node-bootcamp icon indicating copy to clipboard operation
complete-node-bootcamp copied to clipboard

120 Handling Mongoose Validation Errors - overwhelmed with errors over object destructuring

Open hazartilirot opened this issue 5 years ago • 3 comments

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...).

destrucuring_err

hazartilirot avatar Oct 15 '20 20:10 hazartilirot

let error = {...err, message: err.message, name: err.name}; -- here is fix

todorpavlovic avatar Nov 02 '20 18:11 todorpavlovic

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));

abhiippili avatar Jan 04 '23 07:01 abhiippili

the request is hanging when i change the env value to production can someone explain that to me why

Medo3-coder avatar Nov 09 '23 15:11 Medo3-coder