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

Function TestErrorWithHeaders

error_test.go:140–165  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

138}
139
140func TestErrorWithHeaders(t *testing.T) {
141 _, api := humatest.New(t, huma.DefaultConfig("Test API", "1.0.0"))
142 huma.Get(api, "/test", func(ctx context.Context, input *struct{}) (*struct{}, error) {
143 err := huma.ErrorWithHeaders(
144 huma.Error400BadRequest("test"),
145 http.Header{
146 "My-Header": {"bar"},
147 },
148 )
149
150 assert.Equal(t, "test", err.Error())
151
152 // Call again and have all the headers merged
153 err = huma.ErrorWithHeaders(err, http.Header{
154 "Another": {"bar"},
155 })
156
157 return nil, fmt.Errorf("wrapped: %w", err)
158 })
159
160 resp := api.Get("/test")
161 assert.Equal(t, 400, resp.Code)
162 assert.Equal(t, "bar", resp.Header().Get("My-Header"))
163 assert.Equal(t, "bar", resp.Header().Get("Another"))
164 assert.Contains(t, resp.Body.String(), "test")
165}

Callers

nothing calls this directly

Calls 5

NewFunction · 0.92
GetMethod · 0.65
ErrorMethod · 0.65
HeaderMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…