[Kimchi-devel] [PATCH 1/4] Add ResourceAlreadyExists Exception (HTTP 409)

Hongliang Wang hlwang at linux.vnet.ibm.com
Fri Jun 13 02:09:27 UTC 2014


On 06/13/2014 02:03 AM, Aline Manera wrote:
> On 06/12/2014 04:07 AM, Hongliang Wang wrote:
>> When user tries to create a resource with an existing name, we should return
>> HTTP 409 status code to tell the user and let him/her choose another one.
>>
>> Signed-off-by: Hongliang Wang<hlwang at linux.vnet.ibm.com>
>> ---
>>   src/kimchi/control/base.py | 3 +++
>>   src/kimchi/exception.py    | 4 ++++
>>   2 files changed, 7 insertions(+)
>>
>> diff --git a/src/kimchi/control/base.py b/src/kimchi/control/base.py
>> index f8a5210..aaa479d 100644
>> --- a/src/kimchi/control/base.py
>> +++ b/src/kimchi/control/base.py
>> @@ -28,6 +28,7 @@ from kimchi.control.utils import validate_params
>>   from kimchi.exception import InvalidOperation, InvalidParameter
>>   from kimchi.exception import KimchiException
>>   from kimchi.exception import MissingParameter, NotFoundError,  OperationFailed
>> +from kimchi.exception import ResourceAlreadyExists
>>
>>
>>   class Resource(object):
>> @@ -84,6 +85,8 @@ class Resource(object):
>>                   raise cherrypy.HTTPError(400, e.message)
>>               except InvalidOperation, e:
>>                   raise cherrypy.HTTPError(400, e.message)
>> +            except ResourceAlreadyExists, e:
>> +                raise cherrypy.HTTPError(409, e.message)
>>               except OperationFailed, e:
>>                   raise cherrypy.HTTPError(500, e.message)
>>               except NotFoundError, e:
>> diff --git a/src/kimchi/exception.py b/src/kimchi/exception.py
>> index fcf60cc..38daeab 100644
>> --- a/src/kimchi/exception.py
>> +++ b/src/kimchi/exception.py
>> @@ -91,3 +91,7 @@ class IsoFormatError(KimchiException):
>>
>>   class TimeoutExpired(KimchiException):
>>       pass
>> +
>> +
>> +class ResourceAlreadyExists(KimchiException):
>> +    pass
>
> You don't need to create a new exception type
> In those situation, we use InvalidParameter()
I noticed that and was to use InvalidParameter() though I found it only 
returns 400 which is not that specific for existing resource error. When 
we use InvalidParameter with HTTP status code 400, the user can only 
knows some parameter is wrong which is relatively general. If we use 
409, the use will definitely know the given name conflicts with an 
existing one. So I suggest 409 here.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ovirt.org/pipermail/kimchi-devel/attachments/20140613/31e04b35/attachment.html>


More information about the Kimchi-devel mailing list