From 877af4eef35bf4e230b20239b8e0145bb882bc86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Goran=20Meki=C4=87?= Date: Fri, 22 Jul 2016 13:19:57 +0200 Subject: [PATCH] Check if ID is valid --- onelove/api/cluster_services.py | 3 +++ onelove/api/service.py | 2 -- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/onelove/api/cluster_services.py b/onelove/api/cluster_services.py index 9f80aeb..c09cc59 100644 --- a/onelove/api/cluster_services.py +++ b/onelove/api/cluster_services.py @@ -1,4 +1,5 @@ from flask_restplus import abort +from mongoengine.errors import ValidationError from ..models import Service from .fields.cluster_service import post_fields @@ -45,6 +46,8 @@ def post(self, cluster_id): service = Service.objects.get(id=service_id) except Service.DoesNotExist: abort(404, 'No such service') + except ValidationError as e: + abort(409, e.message) cluster.services.append(service) cluster.save() diff --git a/onelove/api/service.py b/onelove/api/service.py index d9ff6d9..9556a54 100644 --- a/onelove/api/service.py +++ b/onelove/api/service.py @@ -55,8 +55,6 @@ def get(self, id): service = self._find_service(id) return service - @ns_service.expect(fields) - @ns_service.marshal_with(get_fields) @ns_service.expect(fields) @ns_service.marshal_with(get_fields) def patch(self, id):