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
16
gorm.go
16
gorm.go
|
@ -347,14 +347,16 @@ func (db *DB) Callback() *callbacks {
|
||||||
|
|
||||||
// AddError add error to db
|
// AddError add error to db
|
||||||
func (db *DB) AddError(err error) error {
|
func (db *DB) AddError(err error) error {
|
||||||
if errTranslator, ok := db.Dialector.(ErrorTranslator); ok {
|
if err != nil {
|
||||||
err = errTranslator.Translate(err)
|
if errTranslator, ok := db.Dialector.(ErrorTranslator); ok {
|
||||||
}
|
err = errTranslator.Translate(err)
|
||||||
|
}
|
||||||
|
|
||||||
if db.Error == nil {
|
if db.Error == nil {
|
||||||
db.Error = err
|
db.Error = err
|
||||||
} else if err != nil {
|
} else {
|
||||||
db.Error = fmt.Errorf("%v; %w", db.Error, err)
|
db.Error = fmt.Errorf("%v; %w", db.Error, err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return db.Error
|
return db.Error
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue