oapi-codegen icon indicating copy to clipboard operation
oapi-codegen copied to clipboard

Allow strict server to return an internal error for logging and a response body

Open pathakhimanshucs opened this issue 1 year ago • 0 comments

I am using the strict server and I would like to define a specific response return to the client and also an internal error.

The strict server interface looks like this FindPets(ctx context.Context, request FindPetsRequestObject) (FindPetsResponseObject, error)

When you return FindPets401JSONResponse{}, nil the correct status code of 401 is encoded

However when you for example return FindPets401JSONResponse{}, fmt.Errorf("invalid authentication... internal details") the response gets overwritten with a status code 500 Internal Server Error and a generic response is returned.

I would like to make it so that the error returned from the handler is available to be logged internally while the response body is still returned to the client with the supplied response object.

Eg in the Echo framework it would look possible something like this echo.NewHTTPError(<status code>, <response object>).WithInternal(<error returned from handler>)

pathakhimanshucs avatar Oct 03 '24 12:10 pathakhimanshucs