@@ -125,7 +125,7 @@ def post_collection(self, class_name, input):
125125 # check for the key property
126126 key = class_obj .getkey ()
127127 if key and key not in props :
128- raise UsageError (' Must provide the "%s" property.' % key )
128+ raise UsageError (" Must provide the '%s' property." % key )
129129
130130 for key in props :
131131 if not self .db .security .hasPermission ('Create' , self .db .getuid (),
@@ -138,7 +138,9 @@ def post_collection(self, class_name, input):
138138 item_id = class_obj .create (** props )
139139 self .db .commit ()
140140 except (TypeError , IndexError , ValueError ), message :
141- raise UsageError (message )
141+ raise ValueError (message )
142+ except KeyError , msg :
143+ raise UsageError ("Must provide the %s property." % msg )
142144
143145 # set the header Location
144146 link = self .base_path + class_name + item_id
@@ -152,10 +154,10 @@ def post_collection(self, class_name, input):
152154 return 201 , result
153155
154156 def post_element (self , class_name , item_id , input ):
155- raise Reject ('Invalid request ' )
157+ raise Reject ('POST to an item is not allowed ' )
156158
157159 def put_collection (self , class_name , input ):
158- raise Reject ('Invalid request ' )
160+ raise Reject ('PUT a class is not allowed ' )
159161
160162 def put_element (self , class_name , item_id , input ):
161163 class_obj = self .db .getclass (class_name )
@@ -170,7 +172,7 @@ def put_element(self, class_name, item_id, input):
170172 result = class_obj .set (item_id , ** props )
171173 self .db .commit ()
172174 except (TypeError , IndexError , ValueError ), message :
173- raise UsageError (message )
175+ raise ValueError (message )
174176
175177 result = {
176178 'id' : item_id ,
@@ -219,7 +221,7 @@ def delete_element(self, class_name, item_id, input):
219221 return 200 , result
220222
221223 def patch_collection (self , class_name , input ):
222- raise Reject ('Invalid request ' )
224+ raise Reject ('PATCH a class is not allowed ' )
223225
224226 def patch_element (self , class_name , item_id , input ):
225227 raise NotImplementedError
@@ -288,8 +290,11 @@ def dispatch(self, method, uri, input):
288290 output = error_obj (400 , msg )
289291 self .client .response_code = 400
290292 except (AttributeError , Reject ), msg :
291- output = error_obj (405 , 'Method Not Allowed. ' + str ( msg ) )
293+ output = error_obj (405 , msg )
292294 self .client .response_code = 405
295+ except ValueError , msg :
296+ output = error_obj (409 , msg )
297+ self .client .response_code = 409
293298 except NotImplementedError :
294299 output = error_obj (402 , 'Method is under development' )
295300 self .client .response_code = 402
0 commit comments