Skip to content

fix APIError to always report errors#243

Merged
casualjim merged 1 commit intogo-openapi:masterfrom
eluv-io:fix-api-errors
May 5, 2022
Merged

fix APIError to always report errors#243
casualjim merged 1 commit intogo-openapi:masterfrom
eluv-io:fix-api-errors

Conversation

@elv-gilles
Copy link
Copy Markdown
Contributor

Command swagger generate client is generating client code looking like this:

// ReadResponse reads a server response into the received o.
func (o *DownloadQPartReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {


	readResponseError := func(err error) error {
		if response.Code()/100 == 2 {
			// that's a real error reading the response,
			// we might as well discard the response code ...
			return runtime.NewAPIError("read response", err, response.Code())
		}
		// now we're reading a potential error.. but if none don't say it's an error
		if err == io.EOF {
			err = nil
		}
		return runtime.NewAPIError("read response", err, response.Code())
	}

	switch response.Code() {

	case 200:
...

With errors that do not implement json marshalling the original error is wipped of the output:

cause [read response (status 200): {}]

After applying the patch:

cause [read response (status 200): 'write /path/to/my/file: no space left on device']

* add unit-test

Signed-off-by: elv-gilles <gilles.gaillard@eluv.io>
@codecov
Copy link
Copy Markdown

codecov Bot commented May 5, 2022

Codecov Report

Merging #243 (87042d5) into master (6df43e7) will increase coverage by 0.21%.
The diff coverage is 50.00%.

@@            Coverage Diff             @@
##           master     #243      +/-   ##
==========================================
+ Coverage   79.94%   80.16%   +0.21%     
==========================================
  Files          42       42              
  Lines        3181     3186       +5     
==========================================
+ Hits         2543     2554      +11     
+ Misses        526      519       -7     
- Partials      112      113       +1     
Impacted Files Coverage Δ
client_response.go 46.42% <50.00%> (+37.73%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6df43e7...87042d5. Read the comment docs.

@casualjim casualjim merged commit 3f9800f into go-openapi:master May 5, 2022
@elv-gilles elv-gilles deleted the fix-api-errors branch May 5, 2022 21:51
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.

2 participants