Skip to content

Commit

Permalink
Revert "added 23503 pgerrcode support and updated the error conversio…
Browse files Browse the repository at this point in the history
…n approach (#185)"

This reverts commit b320a5c.
  • Loading branch information
Saeid Saeidee committed May 19, 2023
1 parent d616c6a commit 90cb42b
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions error_translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import (
"gorm.io/gorm"
)

var errDesToGormErrs = map[string]error{
"23505": gorm.ErrDuplicatedKey,
"23503": gorm.ErrForeignKeyViolated,
var errCodes = map[string]string{
"uniqueConstraint": "23505",
}

type ErrMessage struct {
Expand All @@ -21,9 +20,8 @@ type ErrMessage struct {
// Since currently gorm supporting both pgx and pg drivers, only checking for pgx PgError types is not enough for translating errors, so we have additional error json marshal fallback.
func (dialector Dialector) Translate(err error) error {
if pgErr, ok := err.(*pgconn.PgError); ok {
gormErr, ok := errDesToGormErrs[pgErr.Code]
if ok {
return gormErr
if pgErr.Code == errCodes["uniqueConstraint"] {
return gorm.ErrDuplicatedKey
}
return err
}
Expand Down

0 comments on commit 90cb42b

Please sign in to comment.