fix: kling risk fail return openAIVideo error#3148
Conversation
WalkthroughAdds error handling for failed Kling tasks in the adaptor by populating the OpenAI video error field with task failure details from the Kling response when a task completes with "failed" status. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
relay/channel/task/kling/adaptor.go (1)
408-414: LGTM - Correctly handles task-level failure for risk control scenarios.This change properly populates the error when the Kling API succeeds (
Code == 0) but the task itself fails (e.g., due to risk control). The logic aligns with the PR objective showing the expected response with"status": "failed"and the error message.One minor observation: the existing error handling (lines 402-406) sets both
MessageandCode, whereas this new block only setsMessage. This matches the PR screenshot ("code": ""), but for consistency, consider populating theCodefield:💡 Optional: Add Code field for consistency
if data := klingResp.Data; data.TaskStatus == "failed" { openAIVideo.Error = &dto.OpenAIVideoError{ Message: data.TaskStatusMsg, + Code: "task_failed", } }Also note: if both
klingResp.Code != 0anddata.TaskStatus == "failed"are true (unlikely but possible), this block would overwrite the earlier error set at lines 402-406, losing the original error code. If preserving the API-level error is desired, consider adding anelseor checkingopenAIVideo.Error == nil:if data := klingResp.Data; data.TaskStatus == "failed" && openAIVideo.Error == nil {🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@relay/channel/task/kling/adaptor.go` around lines 408 - 414, The new block sets openAIVideo.Error with only Message when klingResp.Data.TaskStatus == "failed", which can be inconsistent with the earlier error handling that sets both Message and Code and may overwrite an API-level error; update the block that creates dto.OpenAIVideoError to also populate the Code field (e.g., set Code to data.TaskStatus or an appropriate constant) and guard against clobbering an existing error by only setting openAIVideo.Error when openAIVideo.Error == nil or by making the task-status branch an else to the klingResp.Code != 0 branch so the original API error code is preserved.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@relay/channel/task/kling/adaptor.go`:
- Around line 408-414: The new block sets openAIVideo.Error with only Message
when klingResp.Data.TaskStatus == "failed", which can be inconsistent with the
earlier error handling that sets both Message and Code and may overwrite an
API-level error; update the block that creates dto.OpenAIVideoError to also
populate the Code field (e.g., set Code to data.TaskStatus or an appropriate
constant) and guard against clobbering an existing error by only setting
openAIVideo.Error when openAIVideo.Error == nil or by making the task-status
branch an else to the klingResp.Code != 0 branch so the original API error code
is preserved.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: d7c1a43e-505d-4e85-9838-0af18066dfb7
📒 Files selected for processing (1)
relay/channel/task/kling/adaptor.go
…4f8a4248b0ab3b03ba703796ea3 fix: kling risk fail return openAIVideo error
可灵视频被风控时返回标准错误

Summary by CodeRabbit