Skip to content
This repository was archived by the owner on Jan 3, 2026. It is now read-only.

fix: no content response handling when the response type is json#740

Merged
leahecole merged 8 commits intogoogleapis:mainfrom
hakimio:fix-json-error
Oct 14, 2025
Merged

fix: no content response handling when the response type is json#740
leahecole merged 8 commits intogoogleapis:mainfrom
hakimio:fix-json-error

Conversation

@hakimio
Copy link
Copy Markdown
Contributor

@hakimio hakimio commented Sep 23, 2025

Description

Fixes another regression caused by #617
Before the change json parsing was wrapped in a try/catch block and returned empty string in case it failed (line 183 in original gaxios.ts). The change removed the try/catch and just left plain res.json() call.
Now when the server returns 204 No Content response with empty body and responseType is set to json in request config, gaxios throws Unexpected end of JSON input error.
As a possible solution, we now check specifically for No Content response and just return an empty string in that case like before.

Extra test was added to check for this specific case.

Additional Information

Another possible solution could be to return the try/catch block instead of targeting 204 No Content response specifically.

@leahecole please review when you have time.

@hakimio hakimio requested a review from a team September 23, 2025 15:56
@product-auto-label product-auto-label bot added the size: s Pull request size is small. label Sep 23, 2025
@hakimio hakimio changed the title fix: "no content" response handling when the response type is "json" fix: no content response handling when the response type is json Sep 23, 2025
@leahecole
Copy link
Copy Markdown
Contributor

Not sure if it'll be me who reviews, but for whoever does review, adding googleapis/gax-nodejs#1736 as additional context - I think this is pretty similar

@hakimio
Copy link
Copy Markdown
Contributor Author

hakimio commented Sep 23, 2025

Just for reference: the same try/catch logic was left in getResponseDataFromContentType(), but removed from getResponseData(). So, it might make sense to simply return the missing try/catch to getResponseData() like it was prior to #617.

@leahecole leahecole added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Sep 23, 2025
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Sep 23, 2025
@leahecole leahecole added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Sep 23, 2025
@yoshi-kokoro yoshi-kokoro removed kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Sep 23, 2025
@hakimio
Copy link
Copy Markdown
Contributor Author

hakimio commented Sep 24, 2025

@sofisl please review the PR.

@product-auto-label product-auto-label bot removed the size: s Pull request size is small. label Oct 1, 2025
…to fix-json-error

# Conflicts:
#	test/test.getch.ts
@product-auto-label product-auto-label bot added the size: m Pull request size is medium. label Oct 1, 2025
@hakimio
Copy link
Copy Markdown
Contributor Author

hakimio commented Oct 1, 2025

Returned the try/catch block and added an extra test for invalid json.

@hakimio hakimio requested a review from sofisl October 6, 2025 11:59
@hakimio
Copy link
Copy Markdown
Contributor Author

hakimio commented Oct 9, 2025

@ddelgrosso1 can you also check this PR?

Copy link
Copy Markdown

@feywind feywind left a comment

Choose a reason for hiding this comment

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

This looks fine to me, though fyi, tagging many people won't help it get reviewed faster. :) We do this stuff on rotation.

@feywind feywind added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 9, 2025
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 9, 2025
@feywind feywind added the owlbot:run Add this label to trigger the Owlbot post processor. label Oct 9, 2025
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Oct 9, 2025
@leahecole leahecole merged commit ee144e3 into googleapis:main Oct 14, 2025
15 of 18 checks passed
@hakimio
Copy link
Copy Markdown
Contributor Author

hakimio commented Oct 27, 2025

@leahecole Can you release a new version with the bugfix?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

size: m Pull request size is medium.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants