Skip to content

fix: get video task err when Content-Type=json - #1779

Merged
seefs001 merged 2 commits into
QuantumNous:alphafrom
feitianbubu:pr/fix-video-get-task
Oct 2, 2025
Merged

fix: get video task err when Content-Type=json#1779
seefs001 merged 2 commits into
QuantumNous:alphafrom
feitianbubu:pr/fix-video-get-task

Conversation

@feitianbubu

@feitianbubu feitianbubu commented Sep 11, 2025

Copy link
Copy Markdown
Member

修复get task在序列化body时报错的问题
修正为只有在post的时候才UnmarshalBody

Summary by CodeRabbit

  • Bug Fixes
    • Improved error handling for POST /v1/video/generations with a clearer message when the request body is invalid, resulting in more informative feedback.
  • Performance
    • Skips unnecessary body parsing for non-POST requests on /v1/video/generations, reducing overhead and improving reliability.

@coderabbitai

coderabbitai Bot commented Sep 11, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

Relocates request body unmarshalling to only occur for POST on /v1/video/generations, adds an early return with a video-specific error on unmarshal failure, and leaves GET handling unchanged (setting relay mode to VideoFetchByID). This adjusts control flow to avoid parsing bodies for non-POST requests.

Changes

Cohort / File(s) Summary
Video generations request handling
middleware/distributor.go
Move UnmarshalBodyReusable into POST branch for /v1/video/generations; add early-return with message "video无效的请求, " + err.Error() on unmarshal error; keep GET branch setting relay mode to VideoFetchByID; no public API changes.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant C as Client
  participant M as middleware/distributor

  rect rgb(245,248,255)
    note over M: Route: /v1/video/generations
    C->>M: HTTP request (GET or POST)
    alt POST
      M->>M: UnmarshalBodyReusable()
      alt Unmarshal fails
        M-->>C: 4xx error "video无效的请求, {err}"
      else Success
        M->>M: Proceed with POST processing
        M-->>C: Response (POST flow)
      end
    else GET
      M->>M: Set relay mode = VideoFetchByID
      M-->>C: Response (GET flow)
    end
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Pre-merge checks (2 passed, 1 warning)

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title accurately names the primary fix: it addresses GET video-task errors caused by requests with Content-Type: json by restricting UnmarshalBody to POST requests, which matches the PR description and code changes. It is concise and focused so a teammate scanning history will understand the primary intent.

Poem

I twitch my whiskers, code hops neat,
POST gets parsed, GET keeps its feet.
If bodies bungle, errors sing,
“视频无效”—a truthful ring.
Control flows smooth, no extra chew—
A tidy trail for carrots new. 🥕

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title clearly describes the primary fix for GET video task errors when the Content-Type is JSON, aligning with the changes that limit body unmarshalling to POST requests and prevent parse failures on GET.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
middleware/distributor.go (1)

171-174: Unify error message and wrap the cause to avoid double prefixes.

Distribute() prefixes returned errors with "Invalid request, ...". Returning "video无效的请求, ..." here results in "Invalid request, video无效的请求, ...". Prefer a single, consistent message and wrap the original error for traceability.

Apply:

-            if err != nil {
-                return nil, false, errors.New("video无效的请求, " + err.Error())
-            }
+            if err != nil {
+                return nil, false, fmt.Errorf("无效的请求, %w", err)
+            }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 041782c and 4658309.

📒 Files selected for processing (1)
  • middleware/distributor.go (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
middleware/distributor.go (1)
common/gin.go (1)
  • UnmarshalBodyReusable (30-51)
🔇 Additional comments (1)
middleware/distributor.go (1)

171-174: POST-only body unmarshal fixes GET breakage — good change.

Limiting UnmarshalBodyReusable to POST under /v1/video/generations prevents erroneous parsing on GET when Content-Type is application/json. This aligns with the PR goal and avoids the earlier GET task failure.

@seefs001
seefs001 changed the base branch from main to alpha September 22, 2025 05:17
@seefs001
seefs001 changed the base branch from alpha to main September 22, 2025 05:17
@seefs001

Copy link
Copy Markdown
Collaborator

帮忙解决一下冲突

@seefs001
seefs001 changed the base branch from main to alpha October 2, 2025 06:42
@seefs001
seefs001 merged commit 4137120 into QuantumNous:alpha Oct 2, 2025
x22x22 pushed a commit to x22x22/new-api that referenced this pull request Apr 24, 2026
…-task

fix: get video task err when Content-Type=json
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