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)
| 80 | // NewError; this is the fallback so every error still carries a non-empty, |
| 81 | // branchable code. |
| 82 | func 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 |
no outgoing calls