mirror of
https://github.com/OwO-Network/DeepLX.git
synced 2026-12-01 23:07:51 +00:00
fix(translate): answer an empty text list with an empty list, not 404
`"text": []` names a list that happens to be empty, and the response can
render that perfectly well, so rejecting it bought nothing: it was the
original "No text to translate" condition surviving for the one shape the
code had no answer to. It is answered with `{"data": []}` now — the same
rule as every other text, applied to none of them.
A body that never named `text` is a different thing, a payload without its
parameter: it answers 400 Invalid request payload instead of the 404 that
stood in for it, which is also what the endpoint answers for a body it
cannot bind. That is the only refusal left.
Refs #244.
This commit is contained in:
@@ -159,6 +159,17 @@ func Router(cfg *Config) *gin.Engine {
|
||||
return
|
||||
}
|
||||
|
||||
// A body without `text` never named a text to translate, which is a
|
||||
// payload error. `"text": []` names a list that happens to be empty,
|
||||
// and is answered with an empty list, so it is not caught here.
|
||||
if !req.Text.Batch && len(req.Text.Texts) == 0 {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"code": http.StatusBadRequest,
|
||||
"message": "Invalid request payload",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
sourceLang := req.SourceLang
|
||||
targetLang := req.TargetLang
|
||||
texts := req.Text.Texts
|
||||
|
||||
Reference in New Issue
Block a user