Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow resolvers to set a custom response status code #152

Merged
merged 2 commits into from
Oct 23, 2023

Conversation

danielgtaylor
Copy link
Owner

Enable resolvers to return an error which satisfies huma.StatusError in order to set a custom response status code. This means the utility HTTP errors can be used, like huma.Error403Forbidden, if desired, but also anything that implements that interface will work.

Here's a minimal example:

type MyInput struct{}

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

Note: errors are processed in-order and the last one wins. It's best to use this feature very sparingly.

Fixes #107.

@danielgtaylor danielgtaylor merged commit 5265385 into main Oct 23, 2023
1 check passed
@danielgtaylor danielgtaylor deleted the resolver-custom-status branch October 23, 2023 06:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow overriding http status codes from Resolve methods
1 participant