Skip to content
Discussion options

You must be logged in to vote

Please have a look at the generated code, as it heavily depends on the path you're accessing.

Taken the common PetStore specification, there's only one point where this callback is added:

// CreatePets operation middleware
func (sh *strictHandler) CreatePets(w http.ResponseWriter, r *http.Request) {
	var request CreatePetsRequestObject

	var body CreatePetsJSONRequestBody
	if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
		sh.options.RequestErrorHandlerFunc(w, r, fmt.Errorf("can't decode JSON body: %w", err))
		return
	}
...

So the only way to access this error handler here is by sending a request body that can't be decoded to JSON; like empty, plain text, XML...

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@azrdev
Comment options

Answer selected by azrdev
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