Skip to content
This repository was archived by the owner on Oct 8, 2018. It is now read-only.

Commit 55ff643

Browse files
authored
Add unique violation detection to MySQL (#6)
Signed-off-by: arekkas <[email protected]>
1 parent d83ea24 commit 55ff643

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

error.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package sqlcon
22

33
import (
4+
"database/sql"
45
"net/http"
56

6-
"database/sql"
77
"github.com/go-sql-driver/mysql"
88
"github.com/lib/pq"
99
"github.com/ory/herodot"
@@ -37,6 +37,10 @@ func HandleError(err error) error {
3737
}
3838

3939
if err, ok := err.(*mysql.MySQLError); ok {
40+
switch err.Number {
41+
case 1062:
42+
return errors.Wrap(ErrUniqueViolation, err.Error())
43+
}
4044
return errors.WithStack(err)
4145
}
4246

0 commit comments

Comments
 (0)