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(api domain)!: improve status handling in API Domain; do not return an error on 404 #870

Merged
merged 1 commit into from
Jan 9, 2025

Conversation

mildwonkey
Copy link
Contributor

Properly handle cases where a non-200 status code is returned and the status text is in the response body - otherwise basically any error would end up in the body as a string (thanks, http/2) and result in an unmarshalling error.

Changes:

  • added a "status" field, which is populated with the http.Status if included in the response, or the text from the http.StatusCode if not.
  • don't error on a 404 (I swear I did that already, so I guess I did it for reals this time)
  • don't try to unmarshal the body into a json object if the return isn't a 2XX

I'm sure I'm missing more edge cases, and welcome any suggestions, but hopefully this is better!

There is a bit of a breaking change, excep;t it's the one I thought I'd already tackled (missed a big one, I guess): we don't return an error on a 404 response (or, theoretically, any other response that isn't very genuinely invalid - the bits I already took care of?); instead we return a DR with the status code and message.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Other (security config, docs update, etc)

Checklist before merging

@mildwonkey mildwonkey marked this pull request as ready for review January 8, 2025 16:53
@mildwonkey mildwonkey requested a review from a team as a code owner January 8, 2025 16:53
Properly handle cases where a non-200 status code is returned and the status text is in the response body - otherwise basically any error would end up in the body as a string (thanks, http/2) and result in an unmarshalling error.

Changes:
- added a "status" field, which is populated with the http.Status if included in the response, or the text from the http.StatusCode if not.
- don't error on a 404 (I swear I did that already, so I guess I did it for reals this time)
- don't try to unmarshal the body into a json object if the return isn't a 2XX

I'm sure I'm missing more edge cases, and welcome any suggestions, but hopefully this is better!
@mildwonkey mildwonkey force-pushed the mildwonkey/api-status-handling branch from 250bf50 to 06b2a56 Compare January 8, 2025 17:45
@mildwonkey mildwonkey merged commit 693db6f into main Jan 9, 2025
10 checks passed
@mildwonkey mildwonkey deleted the mildwonkey/api-status-handling branch January 9, 2025 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

2 participants