summaryrefslogtreecommitdiff
path: root/app/controllers/api/addresses_controller.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers/api/addresses_controller.rb')
-rw-r--r--app/controllers/api/addresses_controller.rb11
1 files changed, 8 insertions, 3 deletions
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