Skip to content

Commit

Permalink
docs: document resolver custom status codes
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgtaylor committed Oct 23, 2023
1 parent f2556c8 commit 03642ab
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,16 @@ func (m *MyInput) Resolve(ctx huma.Context) []error {
}
```

It is also possible for resolvers to return custom HTTP status codes for the response, by returning an error which satisfies the `huma.StatusError` interface. Errors are processed in the order they are returned and the last one wins, so this feature should be used sparingly. For example:

```go
type MyInput struct{}

func (i *MyInput) Resolve(ctx huma.Context) []error {
return []error{huma.Error403Forbidden("nope")}
}
```

> :whale: Exhaustive errors lessen frustration for users. It's better to return three errors in response to one request than to have the user make three requests which each return a new different error.
#### Input Composition
Expand Down

0 comments on commit 03642ab

Please sign in to comment.