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

Function limitEnvelope

internal/httpapi/agents_write.go:258–270  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

256// (code "limit_exceeded") carrying the structured cap details, replacing the
257// legacy bespoke LimitErrorBody with the standardized envelope.
258func 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}

Callers 4

handleCreateAgentMethod · 0.85
handleTestSendMethod · 0.85
deliverMethod · 0.85
handleRegisterDomainMethod · 0.85

Calls 4

IsLimitExceededFunction · 0.92
NewErrorFunction · 0.85
WithDetailsMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected