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

fix: parseResponseBody overrides original error code in case of unmar… #674

Merged
merged 4 commits into from Sep 19, 2023

Conversation

dmartinol
Copy link
Contributor

This closes #673

I'm not sure what is the best practice to notify of the swallowed marshalling error, anyway I think we cannot override the original error received from the server because of that. Please let me know your feedback about this fix.

Note: I found this issue while using gocloak the go client for Keycloak. Un fact, the latest versions of Keycloak have changed the response data for the 404/Not Found responses, and the body is empty instead of containing a JSON document, so the get requests fail with this unexpected end of JSON input error hiding the 404 status code, which is not acceptable.

@dmartinol
Copy link
Contributor Author

BTW: I also added a couple of tests to verify the fix. If you remove the fix in middleware.go the TestNotFoundWithoutError test fails

middleware.go Outdated Show resolved Hide resolved
Copy link
Member

@jeevatkm jeevatkm left a comment

Choose a reason for hiding this comment

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

Thanks, @dmartinol, for updating the PR.

@jeevatkm jeevatkm added this to the v2.9.0 milestone Sep 19, 2023
@codecov
Copy link

codecov bot commented Sep 19, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (d9bcfaa) 95.64% compared to head (6de285e) 95.64%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #674   +/-   ##
=======================================
  Coverage   95.64%   95.64%           
=======================================
  Files          12       12           
  Lines        1606     1608    +2     
=======================================
+ Hits         1536     1538    +2     
  Misses         42       42           
  Partials       28       28           
Files Changed Coverage Δ
middleware.go 92.15% <100.00%> (+0.05%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jeevatkm jeevatkm merged commit ca02e3e into go-resty:master Sep 19, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

parseResponseBody overrides original error code in case of unmarshalling error
2 participants