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

BED-5065: Display better error messages when creating a new user #1001

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

wes-mil
Copy link
Contributor

@wes-mil wes-mil commented Dec 6, 2024

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:
Screenshot from 2024-12-09 14-54-15

Generic errors now display as:
Screenshot from 2024-12-09 14-54-48

Types of changes

  • New feature (non-breaking change which adds functionality)

Checklist:

  • I have met the contributing prerequisites
  • I have ensured that related documentation is up-to-date
    • Open API docs
    • Code comments (GoDocs / JSDocs)
  • I have followed proper test practices
    • Added/updated tests to cover my changes
    • All new and existing tests passed

@wes-mil wes-mil changed the title BED_5065 BED-5065: Display better error messages when creating a new user Dec 6, 2024
@wes-mil wes-mil added enhancement New feature or request user interface A pull request containing changes affecting the UI code. labels Dec 6, 2024
)

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\"") {
Copy link
Contributor

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

Copy link
Contributor Author

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?

Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request user interface A pull request containing changes affecting the UI code.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants