Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve ERR message when DB entry already exists #1096

Open
lebogg opened this issue May 5, 2023 · 0 comments
Open

Improve ERR message when DB entry already exists #1096

lebogg opened this issue May 5, 2023 · 0 comments

Comments

@lebogg
Copy link
Member

lebogg commented May 5, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant