MCPcopy
hub / github.com/danielgtaylor/huma / TestErrorResponses

Function TestErrorResponses

error_test.go:50–105  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

48}
49
50func TestErrorResponses(t *testing.T) {
51 // NotModified has a slightly different signature.
52 assert.Equal(t, 304, huma.Status304NotModified().GetStatus())
53
54 for _, item := range []struct {
55 constructor func(msg string, errs ...error) huma.StatusError
56 expected int
57 }{
58 // Client errors.
59 {huma.Error400BadRequest, 400},
60 {huma.Error401Unauthorized, 401},
61 {huma.Error402PaymentRequired, 402},
62 {huma.Error403Forbidden, 403},
63 {huma.Error404NotFound, 404},
64 {huma.Error405MethodNotAllowed, 405},
65 {huma.Error406NotAcceptable, 406},
66 {huma.Error407ProxyAuthRequired, 407},
67 {huma.Error408RequestTimeout, 408},
68 {huma.Error409Conflict, 409},
69 {huma.Error410Gone, 410},
70 {huma.Error411LengthRequired, 411},
71 {huma.Error412PreconditionFailed, 412},
72 {huma.Error413RequestEntityTooLarge, 413},
73 {huma.Error414RequestURITooLong, 414},
74 {huma.Error415UnsupportedMediaType, 415},
75 {huma.Error416RequestedRangeNotSatisfiable, 416},
76 {huma.Error417ExpectationFailed, 417},
77 {huma.Error418Teapot, 418},
78 {huma.Error421MisdirectedRequest, 421},
79 {huma.Error422UnprocessableEntity, 422},
80 {huma.Error423Locked, 423},
81 {huma.Error424FailedDependency, 424},
82 {huma.Error425TooEarly, 425},
83 {huma.Error426UpgradeRequired, 426},
84 {huma.Error428PreconditionRequired, 428},
85 {huma.Error429TooManyRequests, 429},
86 {huma.Error431RequestHeaderFieldsTooLarge, 431},
87 {huma.Error451UnavailableForLegalReasons, 451},
88
89 // Server errors.
90 {huma.Error500InternalServerError, 500},
91 {huma.Error501NotImplemented, 501},
92 {huma.Error502BadGateway, 502},
93 {huma.Error503ServiceUnavailable, 503},
94 {huma.Error504GatewayTimeout, 504},
95 {huma.Error505HTTPVersionNotSupported, 505},
96 {huma.Error506VariantAlsoNegotiates, 506},
97 {huma.Error507InsufficientStorage, 507},
98 {huma.Error508LoopDetected, 508},
99 {huma.Error510NotExtended, 510},
100 {huma.Error511NetworkAuthenticationRequired, 511},
101 } {
102 err := item.constructor("test")
103 assert.Equal(t, item.expected, err.GetStatus())
104 }
105}
106
107func TestNegotiateError(t *testing.T) {

Callers

nothing calls this directly

Calls 2

GetStatusMethod · 0.65
constructorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…