limitEnvelope translates a limits.LimitExceededError into a 402 envelope (code "limit_exceeded") carrying the structured cap details, replacing the legacy bespoke LimitErrorBody with the standardized envelope.
(err error)
| 256 | // (code "limit_exceeded") carrying the structured cap details, replacing the |
| 257 | // legacy bespoke LimitErrorBody with the standardized envelope. |
| 258 | func limitEnvelope(err error) (*ErrorEnvelope, bool) { |
| 259 | le, ok := limits.IsLimitExceeded(err) |
| 260 | if !ok { |
| 261 | return nil, false |
| 262 | } |
| 263 | return NewError(http.StatusPaymentRequired, "limit_exceeded", le.Error()).WithDetails(map[string]any{ |
| 264 | "resource": le.Resource, |
| 265 | "limit": le.Limit, |
| 266 | "current": le.Current, |
| 267 | "plan_code": le.Limits.PlanCode, |
| 268 | "upgrade_url": le.Limits.UpgradeURL, |
| 269 | }), true |
| 270 | } |
no test coverage detected