5353from .match import match_dates
5454from .sort import sort_objects
5555from .util import (
56+ abort_with_message ,
5657 add_object ,
5758 fix_object_dict ,
5859 get_backlinks ,
@@ -83,7 +84,9 @@ def full_object(
8384 obj .backlinks = get_backlinks (self .db_handle , obj .handle )
8485 if args .get ("soundex" ):
8586 if self .gramps_class_name not in ["Person" , "Family" ]:
86- abort (422 )
87+ abort_with_message (
88+ 422 , f"Option soundex is not allowed for { self .gramps_class_name } "
89+ )
8790 obj .soundex = get_soundex (self .db_handle , obj , self .gramps_class_name )
8891 obj = self .object_extend (obj , args , locale = locale )
8992 if args .get ("profile" ) and (
@@ -147,17 +150,17 @@ def _parse_object(self) -> GrampsObject:
147150 """Parse the object."""
148151 obj_dict = request .json
149152 if obj_dict is None :
150- abort (400 )
153+ abort_with_message (400 , "Empty object" )
151154 if "_class" not in obj_dict :
152155 obj_dict ["_class" ] = self .gramps_class_name
153156 elif obj_dict ["_class" ] != self .gramps_class_name :
154- abort (400 )
157+ abort_with_message (400 , "Wrong object type" )
155158 try :
156159 obj_dict = fix_object_dict (obj_dict )
157- except ValueError :
158- abort (400 )
160+ except ValueError as exc :
161+ abort_with_message (400 , "Error while processing object" )
159162 if not validate_object_dict (obj_dict ):
160- abort (400 )
163+ abort_with_message (400 , "Schema validation failed" )
161164 return from_json (json .dumps (obj_dict ))
162165
163166 def has_handle (self , handle : str ) -> bool :
@@ -249,7 +252,7 @@ def delete(self, handle: str) -> Response:
249252 get_etag = hash_object (obj )
250253 for etag in request .if_match :
251254 if etag != get_etag :
252- abort (412 )
255+ abort_with_message (412 , "Resource does not match provided ETag" )
253256 trans_dict = delete_object (
254257 self .db_handle_writable , handle , self .gramps_class_name
255258 )
@@ -273,16 +276,16 @@ def put(self, handle: str) -> Response:
273276 get_etag = hash_object (obj_old )
274277 for etag in request .if_match :
275278 if etag != get_etag :
276- abort (412 )
279+ abort_with_message (412 , "Resource does not match provided ETag" )
277280 obj = self ._parse_object ()
278281 if not obj :
279- abort (400 )
282+ abort_with_message (400 , "Empty object" )
280283 db_handle = self .db_handle_writable
281284 with DbTxn ("Edit object" , db_handle ) as trans :
282285 try :
283286 update_object (db_handle , obj , trans )
284- except ValueError :
285- abort (400 )
287+ except ValueError as exc :
288+ abort_with_message (400 , "Error while updating object" )
286289 trans_dict = transaction_to_json (trans )
287290 # update search index
288291 tree = get_tree_from_jwt ()
@@ -431,13 +434,13 @@ def post(self) -> Response:
431434 check_quota_people (to_add = 1 )
432435 obj = self ._parse_object ()
433436 if not obj :
434- abort (400 )
437+ abort_with_message (400 , "Empty object" )
435438 db_handle = self .db_handle_writable
436439 with DbTxn ("Add objects" , db_handle ) as trans :
437440 try :
438441 add_object (db_handle , obj , trans , fail_if_exists = True )
439- except ValueError :
440- abort (400 )
442+ except ValueError as exc :
443+ abort_with_message (400 , "Error while adding object" )
441444 trans_dict = transaction_to_json (trans )
442445 # update usage
443446 if self .gramps_class_name == "Person" :
0 commit comments