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

Function writeEnvelope

internal/httpapi/ratelimit.go:106–111  ·  view source on GitHub ↗

writeEnvelope serializes an error envelope directly to the response from a middleware, where there is no handler return value for Huma to render. It stamps the request id so the body matches the stampRequestID transformer on the handler path, and sets headers before the status line.

(ctx huma.Context, env *ErrorEnvelope)

Source from the content-addressed store, hash-verified

104// stamps the request id so the body matches the stampRequestID transformer on
105// the handler path, and sets headers before the status line.
106func writeEnvelope(ctx huma.Context, env *ErrorEnvelope) {
107 env.Err.RequestID = RequestIDFromContext(ctx.Context())
108 ctx.SetHeader("Content-Type", "application/json")
109 ctx.SetStatus(env.status)
110 _ = json.NewEncoder(ctx.BodyWriter()).Encode(env)
111}
112
113// principalCtxKey carries a principal resolved by the rate-limit middleware so
114// the downstream handler's requireUser/requirePrincipal can skip a second auth.

Callers 1

rateLimitMethod · 0.85

Calls 2

RequestIDFromContextFunction · 0.85
SetStatusMethod · 0.45

Tested by

no test coverage detected