From a4e461bccee482c40e69be9310ba12de5d7da59b Mon Sep 17 00:00:00 2001 From: HombreLaser Date: Fri, 24 Mar 2023 20:34:23 -0600 Subject: Fixes de addresses_controller --- app/controllers/api/addresses_controller.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'app/controllers/api') diff --git a/app/controllers/api/addresses_controller.rb b/app/controllers/api/addresses_controller.rb index 4eda02d..ebe129b 100644 --- a/app/controllers/api/addresses_controller.rb +++ b/app/controllers/api/addresses_controller.rb @@ -12,8 +12,13 @@ module Api def create @service = Services::CreateAddressService.new(current_user_account, service_params) - unless @service.call - render json: { error_messages: @service.address.errors.full_messages }, status: :unprocessable_entity + begin + unless @service.call + render json: { error_messages: @service.address.errors.full_messages }, status: :unprocessable_entity + return + end + rescue ActiveRecord::RecordNotUnique + render json: { error_message: 'Ya cuenta con esta dirección' }, status: :unprocessable_entity return end @@ -55,7 +60,7 @@ module Api end def service_params - params.require(:number, :street, :zip_code, :country, :city) + params.permit(:number, :street, :zip_code, :country, :city) end end end -- cgit v1.2.3