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,11 +9,16 @@ class ServicesController < ApplicationController
def create
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')
else
flash[:error] = t('flash.service.create.error')
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
flash[:error] = t('flash.service.create.error')
end
end
if origin