Improve error messaging when trying to attach a service connected to another account

This commit is contained in:
Karina Kwiatek 2022-01-01 18:58:45 +01:00
parent 5ffce61efe
commit fe6dff8ed6
1 changed files with 7 additions and 2 deletions

View File

@ -9,12 +9,17 @@ class ServicesController < ApplicationController
def create def create
service = Service.initialize_from_omniauth( omniauth_hash ) service = Service.initialize_from_omniauth( omniauth_hash )
service.user = current_user
if current_user.services << service if service.save
flash[:success] = t('flash.service.create.success') flash[:success] = t('flash.service.create.success')
else
if service.errors.details.has_key?(:uid) && service.errors.details[:uid].any? { |err| err[:error] == :taken }
flash[:error] = "The #{service.type.split('::').last.titleize} account you are trying to connect is already connected to another #{APP_CONFIG['site_name']} account."
else else
flash[:error] = t('flash.service.create.error') flash[:error] = t('flash.service.create.error')
end end
end
if origin if origin
redirect_to origin redirect_to origin