Skip to content

Improve ERR message when DB entry already exists #1096

@lebogg

Description

@lebogg

When creating a new DB entry that already exists we get the following error:

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
}

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions