Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions error.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ type ErrorDetail struct {
// the client didn't send extra whitespace or help when the client
// did not log an outgoing request.
Value any `json:"value,omitempty" doc:"The value at the given location"`

// Code is a machine-readable identifier for the error type, corresponding
// to one of the validation.Code* constants. It enables programmatic error
// handling without parsing the human-readable Message field.
Code string `json:"code,omitempty" doc:"Machine-readable error code"`

// Params contains the constraint parameters relevant to the error, e.g.
// {"allowed": ["a","b"]} for a CodeExpectedOneOf error or {"min": 3} for
// a CodeExpectedMinLength error. It is omitted when there are no relevant
// parameters.
Params map[string]any `json:"params,omitempty" doc:"Constraint parameters for the error"`
}

// Error returns the error message / satisfies the `error` interface. If a
Expand Down
12 changes: 9 additions & 3 deletions huma_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3333,15 +3333,21 @@ func TestExhaustiveErrors(t *testing.T) {
{
"message": "expected number <= 10",
"location": "path.id",
"value": 15
"value": 15,
"code": "expected_maximum_number",
"params": {"max": 10}
}, {
"message": "expected number >= 1",
"location": "body.count",
"value": -6
"value": -6,
"code": "expected_minimum_number",
"params": {"min": 1}
}, {
"message": "expected length <= 10",
"location": "body.name",
"value": "12345678901"
"value": "12345678901",
"code": "expected_max_length",
"params": {"max": 10}
}, {
"message": "input resolver error",
"location": "path.id",
Expand Down
Loading
Loading