MCPcopy Create free account
hub / github.com/Mnexa-AI/e2a / humaErrorConstructor

Function humaErrorConstructor

internal/httpapi/errors.go:117–144  ·  view source on GitHub ↗

humaErrorConstructor is installed as huma.NewError so that *all* errors — handler-returned, body-validation, content-negotiation — render in the e2a envelope. Huma passes the status, a message, and zero or more detail errors; we fold the detail errors into `details` so field-level validation failure

(status int, message string, errs ...error)

Source from the content-addressed store, hash-verified

115// errors; we fold the detail errors into `details` so field-level
116// validation failures survive.
117func humaErrorConstructor(status int, message string, errs ...error) huma.StatusError {
118 env := &ErrorEnvelope{
119 status: status,
120 Err: ErrorBody{
121 Code: defaultCodeForStatus(status),
122 Message: message,
123 },
124 }
125 if len(errs) > 0 {
126 // huma.ErrorDetailer values carry structured field/location info;
127 // preserve them as-is so validation output stays machine-readable.
128 details := make([]any, 0, len(errs))
129 for _, err := range errs {
130 if err == nil {
131 continue
132 }
133 if d, ok := err.(huma.ErrorDetailer); ok {
134 details = append(details, d.ErrorDetail())
135 } else {
136 details = append(details, map[string]string{"message": err.Error()})
137 }
138 }
139 if len(details) > 0 {
140 env.Err.Details = details
141 }
142 }
143 return env
144}
145
146// stampRequestID is a Huma transformer that copies the per-request id into
147// the error envelope body just before serialization, so the body matches

Callers 1

Calls 3

defaultCodeForStatusFunction · 0.85
makeFunction · 0.85
ErrorMethod · 0.45

Tested by 1