Skip to content

Commit 5adc76f

Browse files
committed
echo: don't put Go err.Error() into HTTP response bodies
The echo wrapper template emits four parameter-bind error paths (path / query / header / cookie) that currently surface the raw runtime/Bind*ParameterWithOptions error into the HTTP response: return echo.NewHTTPError( http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter X: %s", err)) The string returned by err.Error() is implementation detail of runtime/types/parsing — it can include internal struct field names, package-local error wording, or library version-dependent text. Production servers shouldn't echo that to API consumers. Replace each with: // echo (v4) return echo.NewHTTPError( http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter X: '%s'", <user-value>), ).SetInternal(err) // echo v5 — same idea, different API: return echo.NewHTTPError( http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter X: '%s'", <user-value>), ).Wrap(err) The HTTP body now reflects what the caller sent (`ctx.Param(...)` / `ctx.QueryParams().Get(...)` / `valueList[0]` / `cookie.Value`), and the original err is preserved on the echo HTTPError as either SetInternal (v4) or Wrap (v5) so it still flows to server logs but never to the wire. Regenerated test fixtures and examples to match.
1 parent c346d12 commit 5adc76f

11 files changed

Lines changed: 115 additions & 115 deletions

File tree

examples/petstore-expanded/echo-v5/api/petstore-server.gen.go

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/petstore-expanded/echo/api/petstore-server.gen.go

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/test/issues/issue-1180/issue.gen.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/test/issues/issue-312/issue.gen.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/test/issues/issue-grab_import_names/issue.gen.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)