Skip to content

fix: kling risk fail return openAIVideo error#3148

Merged
Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
feitianbubu:pr/d8a25d36204224f8a4248b0ab3b03ba703796ea3
Mar 9, 2026
Merged

fix: kling risk fail return openAIVideo error#3148
Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
feitianbubu:pr/d8a25d36204224f8a4248b0ab3b03ba703796ea3

Conversation

@feitianbubu
Copy link
Copy Markdown
Contributor

@feitianbubu feitianbubu commented Mar 6, 2026

可灵视频被风控时返回标准错误
image

Summary by CodeRabbit

  • Bug Fixes
    • Improved error handling for failed Kling video generation tasks, ensuring error messages are properly captured and communicated to users when a task fails.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 6, 2026

Walkthrough

Adds 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

Cohort / File(s) Summary
Kling Adaptor Error Handling
relay/channel/task/kling/adaptor.go
Added conditional logic in ConvertToOpenAIVideo to populate openAIVideo.Error with TaskStatusMsg when Kling task status is "failed".

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Suggested reviewers

  • seefs001

Poem

🐰 When Kling tasks stumble and fail, dear friend,
We catch the error message before the end,
TaskStatusMsg now tells the tale,
Of why the task did sadly pale,
Hop along, the error flows so well! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: kling risk fail return openAIVideo error' directly addresses the main change: handling Kling task failures due to risk control by returning standard openAIVideo errors.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 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 Message and Code, whereas this new block only sets Message. This matches the PR screenshot ("code": ""), but for consistency, consider populating the Code field:

💡 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 != 0 and data.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 an else or checking openAIVideo.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

📥 Commits

Reviewing files that changed from the base of the PR and between e768ae4 and c3a96bc.

📒 Files selected for processing (1)
  • relay/channel/task/kling/adaptor.go

@Calcium-Ion Calcium-Ion merged commit b0d8b56 into QuantumNous:main Mar 9, 2026
1 check passed
ennnnny pushed a commit to ennnnny/new-api that referenced this pull request Mar 17, 2026
…4f8a4248b0ab3b03ba703796ea3

fix: kling risk fail return openAIVideo error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants