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

Function TestTransformError

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

Source from the content-addressed store, hash-verified

114}
115
116func TestTransformError(t *testing.T) {
117 config := huma.DefaultConfig("Test API", "1.0.0")
118 config.Transformers = []huma.Transformer{
119 func(ctx huma.Context, status string, v any) (any, error) {
120 return nil, errors.New("whoops")
121 },
122 }
123 _, api := humatest.New(t, config)
124
125 req, _ := http.NewRequest("GET", "/", nil)
126 resp := httptest.NewRecorder()
127 ctx := humatest.NewContext(&huma.Operation{}, req, resp)
128
129 require.Error(t, huma.WriteErr(api, ctx, 400, "bad request"))
130}
131
132func TestErrorAs(t *testing.T) {
133 err := fmt.Errorf("wrapped: %w", huma.Error400BadRequest("test"))

Callers

nothing calls this directly

Calls 3

NewFunction · 0.92
NewContextFunction · 0.92
ErrorMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…