An example returns raw internal error text to HTTP clients
Source references: 3The request-handler example directly calls `http.Error(w, err.Error(), 500)`. If adopted in a project, the underlying database or service error is copied into the response.
The response could reveal database details, internal service names, file paths, query information, or other diagnostics that should remain in server-side logs.
This is a copyable request-handler example: when scoped invocation fails, it sends `err.Error()` directly as the body of a 500 response. If the error contains database addresses, query details, internal types, or configuration data, a remote client could see it. The example is not automatically executed, but the risk applies if adopted. A user can ask for a fixed public response while detailed errors are logged only server-side.
func NewUserRoute(repo *UserRepo) RouteResult { return RouteResult{Route: Route{ Pattern: "/users", Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { users, err := repo.List(r.Context()) if err != nil { http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError) return } fmt.Fprintf(w, "%d users", len(users)) }), }}Show 2 other places
err := scope.Invoke(func(h *Handler) error { return h.Serve(w, req) }) if err != nil { http.Error(w, err.Error(), 500) }}func handle(w http.ResponseWriter, req *http.Request) { scope := root.Scope("request") // Request-scoped values must(scope.Provide(func() *http.Request { return req })) must(scope.Provide(func() RequestID { return RequestID(req.Header.Get("X-Request-ID")) })) must(scope.Decorate(func(l *zap.Logger) *zap.Logger { return l.With(zap.String("request_id", req.Header.Get("X-Request-ID"))) })) err := scope.Invoke(func(h *Handler) error { return h.Serve(w, req) }) if err != nil { http.Error(w, err.Error(), 500) }}```