这是indexloc提供的服务,不要输入任何密码
Skip to content

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
@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

2 participants