MCPcopy
hub / github.com/danielgtaylor/huma / ErrorWithHeaders

Function ErrorWithHeaders

error.go:181–195  ·  view source on GitHub ↗

ErrorWithHeaders wraps an error with additional headers to be sent to the client. This is useful for e.g. caching, rate limiting, or other metadata.

(err error, headers http.Header)

Source from the content-addressed store, hash-verified

179// ErrorWithHeaders wraps an error with additional headers to be sent to the
180// client. This is useful for e.g. caching, rate limiting, or other metadata.
181func ErrorWithHeaders(err error, headers http.Header) error {
182 var he HeadersError
183 if errors.As(err, &he) {
184 // There is already a headers error, so we need to merge the headers. This
185 // lets you chain multiple calls together and have all the headers set.
186 orig := he.GetHeaders()
187 for k, values := range headers {
188 for _, v := range values {
189 orig.Add(k, v)
190 }
191 }
192 return err
193 }
194 return &errWithHeaders{err: err, headers: headers}
195}
196
197// NewError creates a new instance of an error model with the given status code,
198// message, and optional error details. If the error details implement the

Callers

nothing calls this directly

Calls 2

GetHeadersMethod · 0.95
AddMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…