Unfriendly error message displayed when OAuth2 user creation fails on duplicate email
Created by: mxmader
I'm running 6.2-stable with google-oauth2 support enabled.
I've already got an account created with a specific email address (standard account created via GitLab UI).
When I attempt a login using my google account (same email address as standard account) I am subsequently presented with the following error message in my browser:
422 The change you wanted was rejected. Maybe you tried to change something you didn't have access to.
With debug logging enabled, I see the following:
Completed 422 Unprocessable Entity in 221ms ActiveRecord::RecordInvalid (Validation failed: Email has already been taken): lib/gitlab/oauth/user.rb:31:in `create' app/controllers/omniauth_callbacks_controller.rb:41:in `handle_omniauth' app/controllers/omniauth_callbacks_controller.rb:4:in `block (2 levels) in ' app/controllers/application_controller.rb:54:in `set_current_user_for_thread'
It would be more helpful to transform the ActiveRecord validation error text "Validation failed: Email has already been taken" into an alert typical of the GitLab login menu style (currently a shaded red box in the footer of the window).
If I hadn't had debug logging enabled, I would not have quickly understood the root cause.