refactor: fix the error flow

This commit is contained in:
Saeid Saeidee 2023-03-08 21:37:26 +01:00
parent 7e84b6b4b5
commit 5dc02dab0e

View File

@ -347,13 +347,15 @@ func (db *DB) Callback() *callbacks {
// AddError add error to db
func (db *DB) AddError(err error) error {
if db.Error == nil {
db.Error = err
} else if err != nil {
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 {
db.Error = fmt.Errorf("%v; %w", db.Error, err)
}
return db.Error