Skip to content

Errors in middlewares - must api be global? #407

Answered by x-user
davidolrik asked this question in Q&A
Discussion options

You must be logged in to vote

Just use closures bro.

// ...

func main() {
	// ...
	api.UseMiddleware(MyMiddleware(api))
	// ...
}

// ...

func MyMiddleware(api huma.API) func(ctx huma.Context, next func(huma.Context)) {
	return func(ctx huma.Context, next func(huma.Context)) {
		// ...
		huma.WriteErr(api, ctx, http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented))
	}
}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by davidolrik
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants