-
Notifications
You must be signed in to change notification settings - Fork 21
Open
Labels
Description
When creating a new DB entry that already exists we get the following error:
clouditor/persistence/gorm/gorm.go
Lines 187 to 193 in aa23384
| func (s *storage) Create(r any) (err error) { | |
| err = s.db.Create(r).Error | |
| if err != nil && (strings.Contains(err.Error(), "constraint failed: UNIQUE constraint failed") || | |
| strings.Contains(err.Error(), "duplicate key value violates unique constraint")) { | |
| return persistence.ErrUniqueConstraintFailed | |
| } |
clouditor/persistence/persistence.go
Line 35 in aa23384
| ErrUniqueConstraintFailed = errors.New("unique constraint failed") |
Couldn't we return sth. like "DB entry already exists" resulting in a more readable error message? Or are there other cases when this message would be inaccurate?
We could also forward this behavior to the individual endpoints which call this method, of course.