Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Golang][client] fix response decode error handling #1291

Conversation

grokify
Copy link
Member

@grokify grokify commented Oct 22, 2018

PR checklist

  • Read the contribution guidelines.
  • Ran the shell script under ./bin/ to update Petstore sample so that CIs can verify the change. (For instance, only need to run ./bin/{LANG}-petstore.sh and ./bin/security/{LANG}-petstore.sh if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in .\bin\windows\.
  • Filed the PR against the correct branch: master, 3.4.x, 4.0.x. Default: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming language.

@antihax @bvwells @kemokemo

Description of the PR

Fix #1287

When encountering a client.decode error, this will return the error message in a GenericOpenAPIError with the response body included. Previously, the error would be dropped silently.

@grokify grokify changed the title Go/client/fix response decode error handling [Golang][client] fix response decode error handling Oct 22, 2018
@grokify
Copy link
Member Author

grokify commented Oct 22, 2018

Core fix: 649e617
Easier readability: 0416cb3

The readability fix moves if localVarHttpResponse.StatusCode < 300 success handling code below error handling code in if localVarHttpResponse.StatusCode >= 300 and removes the < 300 if clause since it is not needed.

Benefits:

  • removes an extra if statement
  • reduces the locations where a success is returned from 2 to 1
  • moves returning a success earlier in the function to the end following standard approach of returning errors early and success at the end

@grokify
Copy link
Member Author

grokify commented Oct 23, 2018

Circle CI failure looks possibly due to a bug in the test server.

This was being skipped before because the decode error was being dropped, which this PR fixes.

https://circleci.com/gh/grokify/openapi-generator/91#tests/containers/1

=== RUN   TestPlaceOrder
--- FAIL: TestPlaceOrder (0.02s)
	store_api_test.go:23: Error while placing order
	store_api_test.go:24: parsing time ""2018-10-29T21:02:19.201+0000"" as ""2006-01-02T15:04:05Z07:00"": cannot parse "+0000"" as "Z07:00"

See the following issue for more info:

#1292

@grokify
Copy link
Member Author

grokify commented Oct 25, 2018

I've done some thinking about this some more. It seems that now that the decode error is being handled, the TestPlaceOrder test is failing due to my read of the RFC 3339 standard.

3 options:

  1. If we merge this and maintain the test without fixing the server, then all builds will start failing which isn't ideal.
  2. The best option seems to be to fix the test server and then merge this in.
  3. If that takes too long, another option may be to temporarily comment out or disable the TestPlaceOrder test and merge this PR, re-enabling the test when the test server response issue can be resolved.

…00` UTC offset present in Petstore test server
@grokify
Copy link
Member Author

grokify commented Oct 25, 2018

In discussion with @wing328, it was confirmed that the Petstore test server datetime issue (#1292) this known and was previously reported in the former issue tracker.

We agreed to disable TestPlaceOrder test for now and we've done similar things in other areas, such as disabling the flake8 tests for the Python client.

In d2c3006, the TestPlaceOrder test has been disabled for now, and only when it encounters the +0000 UTC offset error. Other errors will still be reported.

@wing328 wing328 added this to the 3.3.2 milestone Oct 26, 2018
@wing328 wing328 merged commit ed8433a into OpenAPITools:master Oct 26, 2018
@wing328
Copy link
Member

wing328 commented Oct 31, 2018

@grokify thanks for the PR, which is included in the v3.3.2 release: https://twitter.com/oas_generator/status/1057649626101112832

A-Joshi pushed a commit to ihsmarkitoss/openapi-generator that referenced this pull request Feb 27, 2019
* handle and return API response decode error

* ensure-up-to-date

* refactor go/api.mustache for easier readability

* disable error reporting for TestPlaceOrder with invalid RFC 3339 `+0000` UTC offset present in Petstore test server
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants