Currently we have to use RecordNotFound in chained mode: db.Find(...).RecordNotFound().
This is not very robust if you also want to handle other errors.
You have to do some form of this:
db := db.Find(...)
if db.RecordNotFound() {
// ...
return
}
if db.Error != nil {
// ...
return
}
// ...
Can we instead have something like this:
if err := db.Find(...).Error; err != nil {
if gorm.RecordNotFound(err) {
// ...
} else {
// ...
}
return
}
The proposed code allows for passing errors up the stack and checking them there:
a := func() error {
return db.Find(...).Error
}
if err := a(); err != nil {
if gorm.RecordNotFound(err) {
// ...
} else {
// ...
}
return
}
// ...
Added method gorm.IsRecordNotFoundError
Thank you for your suggestion.
Most helpful comment
Added method
gorm.IsRecordNotFoundErrorThank you for your suggestion.