Не показывать клиенту контекст обёртки ошибок

This commit is contained in:
2026-10-06 15:58:55 +03:00
parent ba535c6ee6
commit 949622ed93
2 changed files with 17 additions and 9 deletions
+4 -2
View File
@@ -319,8 +319,10 @@ func TestUnavailableCauseIsLoggedButNotReturned(t *testing.T) {
})
rec, eb := do(t, e, http.MethodGet, "/down", "", nil)
assertError(t, rec, eb, http.StatusServiceUnavailable, "unavailable")
if strings.Contains(rec.Body.String(), "connection refused") {
t.Fatalf("cause leaked to the client: %s", rec.Body.String())
// Neither the cause nor the wrapping context of internal operations
// ("select user: ...") may reach the client.
if eb.Error.Message != "database unavailable" {
t.Fatalf("client message = %q, want only the application message", eb.Error.Message)
}
if !strings.Contains(logs.String(), "connection refused") || !strings.Contains(logs.String(), eb.Error.RequestID) {
t.Fatalf("log must carry the cause and the request id, got:\n%s", logs.String())