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

[DSET-4072] Include (truncated) response body in the error message in case we fail to parse the response body #29

Merged
merged 8 commits into from
Jun 9, 2023

Conversation

tomaz-s1
Copy link
Collaborator

@tomaz-s1 tomaz-s1 commented Jun 5, 2023

This pull request updates apiCall() function to also log partial raw response body in case we fail to parse response body as JSON.

This will help troubleshooting various edge cases when the API doesn't return valid JSON.

error message in case we fail to parse the response body as JSON.

This will make troubleshooting various edge cases easier.
@codecov-commenter
Copy link

codecov-commenter commented Jun 5, 2023

Codecov Report

Merging #29 (064dbca) into main (8d16acf) will increase coverage by 0.31%.
The diff coverage is 92.11%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #29      +/-   ##
==========================================
+ Coverage   73.42%   73.72%   +0.31%     
==========================================
  Files          10       10              
  Lines        1358     1370      +12     
==========================================
+ Hits          997     1010      +13     
+ Misses        302      299       -3     
- Partials       59       61       +2     
Impacted Files Coverage Δ
pkg/client/add_events.go 84.14% <57.14%> (+0.28%) ⬆️
pkg/client/client.go 85.48% <100.00%> (+0.49%) ⬆️

tomaz-s1 added 2 commits June 5, 2023 12:33
this URL when sending the requests. Also include it with the error
messages to make troubleshooting easier.
@tomaz-s1
Copy link
Collaborator Author

tomaz-s1 commented Jun 5, 2023

I noticed build failed the first time during CI/CD run so I assume there is still some kind of race condition going on during the tests.

@tomaz-s1
Copy link
Collaborator Author

tomaz-s1 commented Jun 5, 2023

I pushed another change so we also log addEvents URL which is used in the errors to make troubleshooting easier.

In ideal world, we would refactor this code some more and have base struct / class for API errors which would carry all the context (response status code, body, endpoint url, request method, etc.) and utilize this everywhere for consistent and useful log and error messages.

@tomaz-s1 tomaz-s1 requested a review from zdaratom-s1 June 6, 2023 07:08
Copy link
Collaborator

@martin-majlis-s1 martin-majlis-s1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But otherwise looks good. :)

pkg/client/add_events.go Show resolved Hide resolved
@tomaz-s1 tomaz-s1 changed the title Include (truncated) response body in the error message in case we fail to parse the response body [DSET-4072] Include (truncated) response body in the error message in case we fail to parse the response body Jun 8, 2023
@tomaz-s1
Copy link
Collaborator Author

tomaz-s1 commented Jun 9, 2023

I added two more test cases - one to assert actual error logged / returned by the client (c04072b) and one to cover API endpoint URL handling (761f154), so this should now be ready for a final review.

pkg/client/client_test.go Show resolved Hide resolved
pkg/client/client_test.go Outdated Show resolved Hide resolved
@tomaz-s1 tomaz-s1 added this pull request to the merge queue Jun 9, 2023
Merged via the queue into main with commit 189c104 Jun 9, 2023
@tomaz-s1 tomaz-s1 deleted the include_truncated_body_on_error branch June 9, 2023 11:44
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.

4 participants