Fix error handling in run_action function in main.py

This commit is contained in:
Théophile Diot 2024-04-18 13:11:52 +02:00
parent f32321cbc7
commit 2e212b45ac
No known key found for this signature in database
GPG key ID: 248FEA4BAE400D06

View file

@ -330,11 +330,12 @@ def run_action(plugin: str, function_name: str = ""):
if tmp_dir:
sys_path.pop()
rmtree(tmp_dir, ignore_errors=True)
app.logger.exception("An error occurred while importing the plugin")
return {"status": "ko", "code": 500, "message": "An error occurred while importing the plugin, see logs for more details"}
res = None
message = None
try:
# Try to get the custom plugin custom function and call it
@ -360,7 +361,8 @@ def run_action(plugin: str, function_name: str = ""):
sys_path.pop()
rmtree(tmp_dir, ignore_errors=True)
app.logger.exception(message)
if message:
app.logger.exception(message)
if message or not isinstance(res, dict) and not res:
return {"status": "ko", "code": 500, "message": message or "The plugin did not return a valid response"}