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: Don't throw for 204 responses #153

Merged
merged 2 commits into from
Feb 28, 2024
Merged

fix: Don't throw for 204 responses #153

merged 2 commits into from
Feb 28, 2024

Conversation

usame-algan
Copy link
Member

What this solves

A 204 response doesn't contain a body so calling response.json() will throw. This is caught locally and we check if there is a content-length: 0 header to cover the case of a 204 response. If there is no such header we throw again. The issue is that by default, the CGW returns 204 responses without such a header as it is not enforced.

To solve this we are explicitely checking for a 204 status and don't call response.json() in that case.

Copy link

github-actions bot commented Feb 28, 2024

ESLint Summary View Full Report

Annotations are provided inline on the Files Changed tab. You can also see all annotations that were generated on the annotations page.

Type Occurrences Fixable
Errors 0 0
Warnings 0 0
Ignored 0 N/A
  • Result: ✅ success
  • Annotations: 0 total

Report generated by eslint-plus-action

@@ -41,7 +41,7 @@ async function parseResponse<T>(resp: Response): Promise<T> {
let json

try {
json = await resp.json()
json = resp.status === 204 ? {} : await resp.json()
Copy link
Member

Choose a reason for hiding this comment

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

Could you add a comment here? I personally didn't know what 204 means and had to look it up.

@usame-algan usame-algan merged commit 66c90c0 into main Feb 28, 2024
4 checks passed
@usame-algan usame-algan deleted the fix-204 branch February 28, 2024 15:52
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