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

Preserve response body on api requests with XML response types. #4180

Merged
merged 7 commits into from Feb 17, 2022

Conversation

taeold
Copy link
Contributor

@taeold taeold commented Feb 17, 2022

Today, apiv2 will try to parse XML responses as JSON with poor results, e.g.

⚠ functions: Upload Error: Unable to parse JSON: SyntaxError: Unexpected token < in JSON at position 0

Error: Unable to parse JSON: SyntaxError: Unexpected token < in JSON at position 0

Here, we explicitly add support for xml as a responseType and deal with it as a string. E.g.

⚠  functions: Upload Error: HTTP Error: 400, <?xml version='1.0' encoding='UTF-8'?><Error><Code>EntityTooLarge</Code><Message>Your proposed upload is larger than the maximum object size specified in your Policy Document.</Message><Details>Content-length exceeds upper bound on range</Details></Error>

Error: HTTP Error: 400, <?xml version='1.0' encoding='UTF-8'?><Error><Code>EntityTooLarge</Code><Message>Your proposed upload is larger than the maximum object size specified in your Policy Document.</Message><Details>Content-length exceeds upper bound on range</Details></Error>

Fixes #4146

@taeold taeold requested a review from bkendall February 17, 2022 14:50
@@ -158,6 +158,7 @@ export async function upload(
method: "PUT",
path: url.pathname,
queryParams: url.searchParams,
responseType: "xml",
Copy link
Contributor

Choose a reason for hiding this comment

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

Forgive me a silly question: could we not just add accept: application/json to get JSON responses from this API? Or does it exclusively respond in XML?

It feels a little weird to add support for XML for a single place - not that it's wrong, but everywhere else returns JSON, so it's an outlier...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's strictly an XML endpoint we are using since the URL returned by GCF when we call "generateUploadURL" works against it:

https://cloud.google.com/storage/docs/xml-api/overview

We could do some work to move everything to JSON API

https://cloud.google.com/storage/docs/json_api/v1/buckets/patch

But that's gonna be a lot more work than this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(Looks like XML is the encoding of choice over JSON in the storage API world)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

whoops more correct answer - signed URL only supports XML API:

https://cloud.google.com/storage/docs/access-control/signed-urls

CHANGELOG.md Outdated Show resolved Hide resolved
Co-authored-by: Bryan Kendall <bkend@google.com>
@taeold taeold requested a review from bkendall February 17, 2022 17:51
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.

Improve error message when function deployment fails because the packaged function source is >100MB
3 participants