From ecdae3e01695e92e54d640911c5164f882ec3cf7 Mon Sep 17 00:00:00 2001 From: HombreLaser Date: Fri, 24 Mar 2023 20:58:33 -0600 Subject: Arregla método update de AddressesController MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/addresses_controller.rb | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'app/controllers/api') diff --git a/app/controllers/api/addresses_controller.rb b/app/controllers/api/addresses_controller.rb index ebe129b..110596c 100644 --- a/app/controllers/api/addresses_controller.rb +++ b/app/controllers/api/addresses_controller.rb @@ -29,14 +29,19 @@ module Api def update @service = Services::UpdateAddressService.new(current_user_account, params[:id], service_params) - case @service.call - when :not_found - render json: { error_message: 'Not found' }, status: :not_found - when :unprocessable_entity - render json: { error_messages: @service.address.errors.full_messages }, status: :unprocessable_entity - else - @address = @service.address - render json: serialized_object.serializable_hash, status: :ok + begin + case @service.call + when :not_found + render json: { error_message: 'Not found' }, status: :not_found + when :unprocessable_entity + render json: { error_messages: @service.address.errors.full_messages }, status: :unprocessable_entity + else + @address = @service.address + render json: serialized_object.serializable_hash, status: :ok + end + rescue ActiveRecord::RecordNotUnique + render json: { error_message: 'Ya cuenta con esta dirección' }, status: :unprocessable_entity + return end end -- cgit v1.2.3