fix: get video task err when Content-Type=json - #1779
Conversation
WalkthroughRelocates 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
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Pre-merge checks (2 passed, 1 warning)❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests
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.
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
📒 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.
|
帮忙解决一下冲突 |
…-task fix: get video task err when Content-Type=json
修复get task在序列化body时报错的问题
修正为只有在post的时候才UnmarshalBody
Summary by CodeRabbit