refactor(api): improve error handling in trigger providers

- Removed unnecessary ValueError handling in TriggerSubscriptionBuilderCreateApi and TriggerSubscriptionBuilderBuildApi, allowing for more streamlined exception management.
- Updated TriggerSubscriptionBuilderVerifyApi and TriggerSubscriptionBuilderBuildApi to raise ValueError with the original exception context for better debugging.
- Enhanced trigger_endpoint in trigger.py to log errors and return a JSON response for not found endpoints, improving user feedback and error reporting.

These changes enhance the robustness and clarity of error handling across the API.
This commit is contained in:
Harry
2025-09-28 13:03:19 +08:00
parent 92f2ca1866
commit 19cc67561b
2 changed files with 4 additions and 7 deletions

View File

@@ -99,8 +99,6 @@ class TriggerSubscriptionBuilderCreateApi(Resource):
credential_type=credential_type,
)
return jsonable_encoder({"subscription_builder": subscription_builder})
except ValueError as e:
raise BadRequest(str(e))
except Exception as e:
logger.exception("Error adding provider credential", exc_info=e)
raise
@@ -151,7 +149,7 @@ class TriggerSubscriptionBuilderVerifyApi(Resource):
)
except Exception as e:
logger.exception("Error verifying provider credential", exc_info=e)
raise
raise ValueError(str(e)) from e
class TriggerSubscriptionBuilderUpdateApi(Resource):
@@ -251,11 +249,9 @@ class TriggerSubscriptionBuilderBuildApi(Resource):
subscription_builder_id=subscription_builder_id,
)
return 200
except ValueError as e:
raise BadRequest(str(e))
except Exception as e:
logger.exception("Error building provider credential", exc_info=e)
raise
raise ValueError(str(e)) from e
class TriggerSubscriptionDeleteApi(Resource):

View File

@@ -33,7 +33,8 @@ def trigger_endpoint(endpoint_id: str):
if response:
break
if not response:
raise NotFound("Endpoint not found")
logger.error("Endpoint not found for {endpoint_id}")
return jsonify({"error": "Endpoint not found"}), 404
return response
except ValueError as e:
raise NotFound(str(e))