47
47
from .report import run_report
48
48
from .resources .delete import delete_all_objects
49
49
from .resources .util import (
50
+ abort_with_message ,
50
51
app_has_semantic_search ,
51
52
dry_run_import ,
52
53
run_import ,
60
61
update_telemetry_timestamp ,
61
62
)
62
63
from .util import (
63
- abort_with_message ,
64
64
check_quota_people ,
65
65
close_db ,
66
66
get_config ,
@@ -76,7 +76,10 @@ def run_task(task: Task, **kwargs) -> Union[AsyncResult, Any]:
76
76
"""Send a task to the task queue or run immediately if no queue set up."""
77
77
if not current_app .config ["CELERY_CONFIG" ]:
78
78
with current_app .app_context ():
79
- return task (** kwargs )
79
+ try :
80
+ return task (** kwargs )
81
+ except Exception as exc :
82
+ abort_with_message (500 , str (exc ))
80
83
return task .delay (** kwargs )
81
84
82
85
@@ -497,7 +500,7 @@ def process_transactions(
497
500
):
498
501
if num_people_added or num_people_deleted :
499
502
update_usage_people (tree = tree , user_id = user_id )
500
- abort_with_message ( 409 , "Object has changed" )
503
+ raise ValueError ( "Object has changed" )
501
504
new_data = item ["new" ]
502
505
if new_data :
503
506
new_obj = gramps_object_from_dict (new_data )
@@ -515,11 +518,11 @@ def process_transactions(
515
518
else :
516
519
if num_people_added or num_people_deleted :
517
520
update_usage_people (tree = tree , user_id = user_id )
518
- abort_with_message ( 400 , "Unexpected transaction type" )
521
+ raise ValueError ( "Unexpected transaction type" )
519
522
except (KeyError , UnicodeDecodeError , json .JSONDecodeError , TypeError ):
520
523
if num_people_added or num_people_deleted :
521
524
update_usage_people (tree = tree , user_id = user_id )
522
- abort_with_message ( 400 , "Error while processing transaction" )
525
+ raise ValueError ( "Error while processing transaction" )
523
526
trans_dict = transaction_to_json (trans )
524
527
finally :
525
528
# close the *writeable* db handle regardless of errors
@@ -570,7 +573,7 @@ def handle_commit(trans: DbTxn, class_name: str, obj) -> None:
570
573
def handle_add (trans : DbTxn , class_name : str , obj ) -> None :
571
574
"""Handle an add action."""
572
575
if class_name != "Tag" and not obj .gramps_id :
573
- abort_with_message ( 400 , "Gramps ID missing" )
576
+ raise ValueError ( "Gramps ID missing" )
574
577
handle_commit (trans , class_name , obj )
575
578
576
579
0 commit comments