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

Function WriteLimitError

internal/limits/http.go:42–59  ·  view source on GitHub ↗

WriteLimitError writes a 402 Payment Required response with the LimitErrorBody payload. Centralized here so every Check* call site in HTTP handlers can convert the typed error uniformly: if err := enforcer.CheckAgentCreate(ctx, userID); err != nil { if limits.WriteLimitError(w, err) { return

(w http.ResponseWriter, err error)

Source from the content-addressed store, hash-verified

40// written; false when the error was something else (caller must handle
41// it themselves, typically as 5xx).
42func WriteLimitError(w http.ResponseWriter, err error) bool {
43 le, ok := IsLimitExceeded(err)
44 if !ok {
45 return false
46 }
47 body := LimitErrorBody{
48 Error: le.Error(),
49 Resource: le.Resource,
50 Limit: le.Limit,
51 Current: le.Current,
52 PlanCode: le.Limits.PlanCode,
53 UpgradeURL: le.Limits.UpgradeURL,
54 }
55 w.Header().Set("Content-Type", "application/json")
56 w.WriteHeader(http.StatusPaymentRequired)
57 _ = json.NewEncoder(w).Encode(body)
58 return true
59}

Callers

nothing calls this directly

Calls 3

IsLimitExceededFunction · 0.85
ErrorMethod · 0.45
WriteHeaderMethod · 0.45

Tested by

no test coverage detected