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

feat(upload): Accept HTTP 200 responses with empty body #184

Conversation

amezcua
Copy link

@amezcua amezcua commented Mar 7, 2024

Summary

When using a third party server, we may encounter valid HTTP 200 responses that do not include a JSON body.

In the current SDK it is assumed that the response always has a JSON form and the request fails otherwise even though the response code is 200.

The failure is due to the creation of a JSONObject(responseBody) object that is passed to the function that creates the HTTP response. If that responseBody is null, empty or does not contain a json string, that call will throw an exception and the request is considered a failure.

In this change, if the response is null or empty, it is still passed to the function that creates the response, and, if it is a 200 response, it will be considered a successful response.

This behavior is equivalent to the behavior of the Amplitude Swift SDK, that accepts empty responses (https://github.com/amplitude/Amplitude-Swift/blob/35f253db41cf68d220390946c7ad7f344665d763/Sources/Amplitude/Utilities/HttpClient.swift#L35)

Checklist

  • Does your PR title have the correct title format?
  • Does your PR have a breaking change?: No

When using a third party server, we may encounter valid HTTP 200 responses that do not include a JSON body.

In the current SDK it is assumed that the response always has a JSON form and the request fails otherwise even though the response code is 200.

The failure is due to the creation of a `JSONObject(responseBody)` object that is passed to the function that creates the HTTP response. If that `responseBody` is null, empty or does not contain a json string, that call will throw an exception and the request is considered a failure.

In this change, if the response is null or empty, it is still passed to the function that creates the response, and, if it is a 200 response, it will be considered a successful response.

This behavior is equivalent to the behavior of the Amplitude Swift SDK, that accepts empty responses (https://github.com/amplitude/Amplitude-Swift/blob/35f253db41cf68d220390946c7ad7f344665d763/Sources/Amplitude/Utilities/HttpClient.swift#L35)
@amezcua amezcua changed the title feat(upload): Accept-HTTP-200-Responses-with-empty-body feat(upload): Accept HTTP 200 responses with empty body Mar 7, 2024
@amezcua
Copy link
Author

amezcua commented Mar 18, 2024

Changes included in #185 (thanks!) closing this one.

@amezcua amezcua closed this Mar 18, 2024
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