From 20cbb4ab3943db996a7b7af2a152eb81db083a7d Mon Sep 17 00:00:00 2001 From: anhduy-tech Date: Tue, 20 Jan 2026 11:33:42 +0700 Subject: [PATCH] changes --- app/workflow_actions.py | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/app/workflow_actions.py b/app/workflow_actions.py index 58b87a86..ff82965e 100644 --- a/app/workflow_actions.py +++ b/app/workflow_actions.py @@ -111,41 +111,66 @@ def api_call_action(params, context): method = params["method"].upper() url = resolve_value(params["url"], context) save_as = params.get("save_as") - + raw_body = params.get("body") - - # Nếu body chứa biểu thức $map, thực hiện biến đổi dữ liệu trước khi gửi + + # ============================ + # Resolve body + # ============================ if isinstance(raw_body, str) and raw_body.startswith("$map"): body = handle_map_expression(raw_body, context) elif isinstance(raw_body, dict): body = deep_resolve_values(raw_body, context) + elif raw_body is None: + body = None else: body = resolve_value(raw_body, context) print(f" [API_CALL] {method} {url}") print(f" [API_CALL] Resolved Body: {body}") - # Thực hiện request + # ============================ + # Execute request + # ============================ if method == "POST": resp = client.post(url, body, content_type="application/json") elif method == "PATCH": resp = client.patch(url, body, content_type="application/json") elif method == "PUT": resp = client.put(url, body, content_type="application/json") + elif method == "DELETE": + resp = client.delete(url) else: resp = client.get(url) print(f" [API_CALL] Status Code: {resp.status_code}") + # ============================ + # Handle error + # ============================ if resp.status_code >= 400: - error_content = resp.content.decode('utf-8') + error_content = resp.content.decode("utf-8") if resp.content else "" print(f" [API_CALL] Error: {error_content}") raise Exception(f"API Call failed: {error_content}") - result = resp.json() + # ============================ + # Handle response safely + # ============================ + if resp.status_code == 204 or not resp.content: + # DELETE / No Content + result = {"deleted": True} + else: + try: + result = resp.json() + except ValueError: + # Fallback nếu response không phải JSON + result = resp.content.decode("utf-8") + print(f" [API_CALL] Result: {result}") + if save_as: context[save_as] = result + return result