mirror of
https://github.com/OwO-Network/DeepLX.git
synced 2026-06-11 15:28:50 +00:00
fix(service): log translation errors and hide internals from clients
Return a generic "Translation failed" message instead of echoing err.Error() in the HTTP response, and log the underlying error server-side via log.Printf. Avoids leaking internal details (proxy address, upstream URL, etc.) to API clients while keeping the 500 behavior introduced in #224.
This commit is contained in:
parent
d19a3902df
commit
9d6b294a61
@ -133,9 +133,10 @@ func Router(cfg *Config) *gin.Engine {
|
|||||||
|
|
||||||
result, err := translate.TranslateByDeepLX(sourceLang, targetLang, translateText, tagHandling, proxyURL, "")
|
result, err := translate.TranslateByDeepLX(sourceLang, targetLang, translateText, tagHandling, proxyURL, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Printf("Translation failed: %s", err)
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{
|
c.JSON(http.StatusInternalServerError, gin.H{
|
||||||
"code": http.StatusInternalServerError,
|
"code": http.StatusInternalServerError,
|
||||||
"message": "Translation failed: " + err.Error(),
|
"message": "Translation failed",
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -207,9 +208,10 @@ func Router(cfg *Config) *gin.Engine {
|
|||||||
|
|
||||||
result, err := translate.TranslateByDeepLX(sourceLang, targetLang, translateText, tagHandling, proxyURL, dlSession)
|
result, err := translate.TranslateByDeepLX(sourceLang, targetLang, translateText, tagHandling, proxyURL, dlSession)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Printf("Translation failed: %s", err)
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{
|
c.JSON(http.StatusInternalServerError, gin.H{
|
||||||
"code": http.StatusInternalServerError,
|
"code": http.StatusInternalServerError,
|
||||||
"message": "Translation failed: " + err.Error(),
|
"message": "Translation failed",
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -263,9 +265,10 @@ func Router(cfg *Config) *gin.Engine {
|
|||||||
|
|
||||||
result, err := translate.TranslateByDeepLX("", targetLang, translateText, "", proxyURL, "")
|
result, err := translate.TranslateByDeepLX("", targetLang, translateText, "", proxyURL, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Printf("Translation failed: %s", err)
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{
|
c.JSON(http.StatusInternalServerError, gin.H{
|
||||||
"code": http.StatusInternalServerError,
|
"code": http.StatusInternalServerError,
|
||||||
"message": "Translation failed: " + err.Error(),
|
"message": "Translation failed",
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user