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)
| 104 | // stamps the request id so the body matches the stampRequestID transformer on |
| 105 | // the handler path, and sets headers before the status line. |
| 106 | func 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. |
no test coverage detected