mirror of https://github.com/go-gorm/gorm.git
refactor: translate error only when it is not nil (#6133)
* refactor: translate error only when it is not nil * refactor: fix the error flow * refactor: update the error if checks * Update gorm.go --------- Co-authored-by: Saeid Saeidee <s.saeidee@sensysgatso.com> Co-authored-by: Jinzhu <wosmvp@gmail.com>
This commit is contained in:
parent
ed474152b1
commit
707d70a542
4
gorm.go
4
gorm.go
|
@ -347,15 +347,17 @@ func (db *DB) Callback() *callbacks {
|
|||
|
||||
// AddError add error to db
|
||||
func (db *DB) AddError(err error) error {
|
||||
if err != nil {
|
||||
if errTranslator, ok := db.Dialector.(ErrorTranslator); ok {
|
||||
err = errTranslator.Translate(err)
|
||||
}
|
||||
|
||||
if db.Error == nil {
|
||||
db.Error = err
|
||||
} else if err != nil {
|
||||
} else {
|
||||
db.Error = fmt.Errorf("%v; %w", db.Error, err)
|
||||
}
|
||||
}
|
||||
return db.Error
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue