Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
148
rated 0 times [  152] [ 4]  / answers: 1 / hits: 21150  / 8 Years ago, sun, march 13, 2016, 12:00:00

This error throws up whenever I enter a duplicate entry in mysql.



{ [Error: ER_DUP_ENTRY: Duplicate entry '[email protected]' for key 'email
'] code: 'ER_DUP_ENTRY', errno: 1062, sqlState: '23000', index: 0 }



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 :



{code:ER_DUP_ENTRY,errno:1062,sqlState:23000,index:0}



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?


More From » mysql

 Answers
17

I thought I had to use JSON for this problem because of the way the Error object was formatted. How I solved this one was just to use



err.toString()

[#62947] Friday, March 11, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
aileent

Total Points: 556
Total Questions: 107
Total Answers: 101

Location: Croatia
Member since Fri, Sep 11, 2020
4 Years ago
;