title: How do I convert an Error object in node js to a string properly?
body: <p>This error throws up whenever I enter a duplicate entry in mysql.</p>
  
  <p><code>{ [Error: ER_DUP_ENTRY: Duplicate entry 'sample@gmail.com' for key 'email
  '] code: 'ER_DUP_ENTRY', errno: 1062, sqlState: '23000', index: 0 }</code></p>
  
  <p>What I want to do is turn this Error object into a string. I tried using JSON.stringify() and when I printed it on the console, only the last part got converted into a string : </p>
  
  <p><code>{"code":"ER_DUP_ENTRY","errno":1062,"sqlState":"23000","index":0}</code></p>
  
  <p>I need to convert the first part as well of the error, the one inside the [ ] so that I am able to diagnose duplicates properly. How do I retrieve that part whenever I convert an Error object into a string?</p>