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

Function defaultCodeForStatus

internal/httpapi/errors.go:82–110  ·  view source on GitHub ↗

defaultCodeForStatus maps an HTTP status to a stable default `code` for the cases where a handler (or Huma's built-in validation) produced only a status + message. Ported handlers should pass an explicit code via NewError; this is the fallback so every error still carries a non-empty, branchable cod

(status int)

Source from the content-addressed store, hash-verified

80// NewError; this is the fallback so every error still carries a non-empty,
81// branchable code.
82func defaultCodeForStatus(status int) string {
83 switch status {
84 case http.StatusBadRequest:
85 return "bad_request"
86 case http.StatusUnauthorized:
87 return "unauthorized"
88 case http.StatusForbidden:
89 return "forbidden"
90 case http.StatusNotFound:
91 return "not_found"
92 case http.StatusMethodNotAllowed:
93 return "method_not_allowed"
94 case http.StatusConflict:
95 return "conflict"
96 case http.StatusRequestEntityTooLarge:
97 return "payload_too_large"
98 case http.StatusUnprocessableEntity:
99 return "unprocessable_entity"
100 case http.StatusTooManyRequests:
101 return "rate_limited"
102 case http.StatusUnsupportedMediaType:
103 return "unsupported_media_type"
104 default:
105 if status >= 500 {
106 return "internal_error"
107 }
108 return "error"
109 }
110}
111
112// humaErrorConstructor is installed as huma.NewError so that *all* errors —
113// handler-returned, body-validation, content-negotiation — render in the

Callers 2

TestDefaultCodeForStatusFunction · 0.85
humaErrorConstructorFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestDefaultCodeForStatusFunction · 0.68