How to parse MySQL errors
<p>I am trying to parse MySQL errors in order to return clean error messages to the user from a Go API.</p>
<p>I read some article like <a href="https://stackoverflow.com/questions/34008600/handle-a-specific-error-in-golang">this one</a> that show what I would like to do but it looks like the module <a href="https://github.com/go-sql-driver/mysql" rel="nofollow noreferrer">go-mysql-driver</a> that I am using doesn't support parseError.</p>
<p>To give a concrete example, with the error:</p>
<pre><code>Error 1062: Duplicate entry 'John' for key 'name_UNIQUE'
</code></pre>
<p>I would like to be able to build a data structure that allow me to organize the information in order to return a user friendly message like</p>
<pre><code>Error with the field 'name': 'John' already exist&quot;
</code></pre>
<p>so I can also translate it in different languages and send ready-to-use error messages back to the client.</p>
<p>Thank you!</p>