-
Notifications
You must be signed in to change notification settings - Fork 119
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
BED-5065: Display better error messages when creating a new user #1001
base: main
Are you sure you want to change the base?
Conversation
Adjust where error is being checked on api
cmd/api/src/database/helper.go
Outdated
) | ||
|
||
func CheckError(tx *gorm.DB) error { | ||
if errors.Is(tx.Error, gorm.ErrRecordNotFound) { | ||
return ErrNotFound | ||
} | ||
|
||
if tx.Error != nil { | ||
if strings.Contains(tx.Error.Error(), "duplicate key value violates unique constraint \"users_principal_name_key\"") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want to keep this function agnostic to any specific db table as it's used across the datalayer. This error handling might be better placed in the db method directly associated with user creation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspected that to be the case, but this error can also be thrown by UpdateUser. I was trying to avoid duplicating code. Would it be better to just have the explicit check in both?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea in both is likely a better place than here IMO
Description
Display more descriptive and better formatted errors when failing to create a new user.
Motivation and Context
This PR addresses: BED-5065
Why is this change required? What problem does it solve?
Previous error message would not indicate to the admin user why creating a new user was failing to be created.
How Has This Been Tested?
Creating a new user with a duplicate principal name now displays a more descriptive error message.
Screenshots (optional):
Duplicate principal name errors now display as:
Generic errors now display as:
Types of changes
Checklist: