Render a more friendly error message for username conflicts
Created by: flying-robot
When there is a username conflict during profile updates, an unfriendly duplicate key constraint error message is surfaced to the user along with a big "Error:" prefix. This runs afoul of our style guidelines and the experience we want our customers to have.
This changes that behavior (using a strategy employed elsewhere in the database code) to sniff out exactly what went wrong, and if it's a duplicate key violation we can show something more helpful ("Username is already in use.") The "Error:" prefix is similarly removed from the form alert.
Note that this only catches the specific case of username conflict. There are multiple returns that simply pass along err
, but that's outside the scope of this change.
Screenshots
Fixes https://github.com/sourcegraph/sourcegraph/issues/17552