feat(upload): Accept HTTP 200 responses with empty body #184
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 thatresponseBody
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