From 9d6b294a6143c7639bf5daf9d06b0f1cc5bcb594 Mon Sep 17 00:00:00 2001 From: Vincent Young Date: Tue, 2 Jun 2026 14:38:02 +0800 Subject: [PATCH] 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. --- service/service.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/service/service.go b/service/service.go index 9d0456f..251d50e 100644 --- a/service/service.go +++ b/service/service.go @@ -133,9 +133,10 @@ func Router(cfg *Config) *gin.Engine { result, err := translate.TranslateByDeepLX(sourceLang, targetLang, translateText, tagHandling, proxyURL, "") if err != nil { + log.Printf("Translation failed: %s", err) c.JSON(http.StatusInternalServerError, gin.H{ "code": http.StatusInternalServerError, - "message": "Translation failed: " + err.Error(), + "message": "Translation failed", }) return } @@ -207,9 +208,10 @@ func Router(cfg *Config) *gin.Engine { result, err := translate.TranslateByDeepLX(sourceLang, targetLang, translateText, tagHandling, proxyURL, dlSession) if err != nil { + log.Printf("Translation failed: %s", err) c.JSON(http.StatusInternalServerError, gin.H{ "code": http.StatusInternalServerError, - "message": "Translation failed: " + err.Error(), + "message": "Translation failed", }) return } @@ -263,9 +265,10 @@ func Router(cfg *Config) *gin.Engine { result, err := translate.TranslateByDeepLX("", targetLang, translateText, "", proxyURL, "") if err != nil { + log.Printf("Translation failed: %s", err) c.JSON(http.StatusInternalServerError, gin.H{ "code": http.StatusInternalServerError, - "message": "Translation failed: " + err.Error(), + "message": "Translation failed", }) return }