From 409efc581c8d8e71956f9c2a6a76b87706f8dd60 Mon Sep 17 00:00:00 2001 From: Kushagra Thapar Date: Fri, 10 Jan 2020 17:04:46 -0800 Subject: [PATCH] Return empty string on empty content response from backend (#7347) --- .../data/cosmos/internal/directconnectivity/ErrorUtils.java | 2 +- .../cosmos/internal/directconnectivity/HttpClientUtils.java | 3 ++- .../data/cosmos/internal/directconnectivity/ResponseUtils.java | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/sdk/cosmos/microsoft-azure-cosmos/src/main/java/com/azure/data/cosmos/internal/directconnectivity/ErrorUtils.java b/sdk/cosmos/microsoft-azure-cosmos/src/main/java/com/azure/data/cosmos/internal/directconnectivity/ErrorUtils.java index 230e28463c69a..1cd0022b2b9c7 100644 --- a/sdk/cosmos/microsoft-azure-cosmos/src/main/java/com/azure/data/cosmos/internal/directconnectivity/ErrorUtils.java +++ b/sdk/cosmos/microsoft-azure-cosmos/src/main/java/com/azure/data/cosmos/internal/directconnectivity/ErrorUtils.java @@ -17,7 +17,7 @@ public class ErrorUtils { private static final Logger logger = LoggerFactory.getLogger(ErrorUtils.class); static Mono getErrorResponseAsync(HttpResponse responseMessage, HttpRequest request) { - Mono responseAsString = responseMessage.bodyAsString(); + Mono responseAsString = responseMessage.bodyAsString().switchIfEmpty(Mono.just(StringUtils.EMPTY)); if (request.httpMethod() == HttpMethod.DELETE) { return Mono.just(StringUtils.EMPTY); } diff --git a/sdk/cosmos/microsoft-azure-cosmos/src/main/java/com/azure/data/cosmos/internal/directconnectivity/HttpClientUtils.java b/sdk/cosmos/microsoft-azure-cosmos/src/main/java/com/azure/data/cosmos/internal/directconnectivity/HttpClientUtils.java index 48d9f571890e2..a3faa38684aa8 100644 --- a/sdk/cosmos/microsoft-azure-cosmos/src/main/java/com/azure/data/cosmos/internal/directconnectivity/HttpClientUtils.java +++ b/sdk/cosmos/microsoft-azure-cosmos/src/main/java/com/azure/data/cosmos/internal/directconnectivity/HttpClientUtils.java @@ -10,6 +10,7 @@ import com.azure.data.cosmos.internal.RxDocumentServiceResponse; import com.azure.data.cosmos.internal.http.HttpRequest; import com.azure.data.cosmos.internal.http.HttpResponse; +import org.apache.commons.lang3.StringUtils; import reactor.core.publisher.Mono; public class HttpClientUtils { @@ -31,7 +32,7 @@ static Mono parseResponseAsync(Mono htt } private static Mono createDocumentClientException(HttpResponse httpResponse) { - Mono readStream = httpResponse.bodyAsString(); + Mono readStream = httpResponse.bodyAsString().switchIfEmpty(Mono.just(StringUtils.EMPTY)); return readStream.map(body -> { CosmosError cosmosError = BridgeInternal.createCosmosError(body); diff --git a/sdk/cosmos/microsoft-azure-cosmos/src/main/java/com/azure/data/cosmos/internal/directconnectivity/ResponseUtils.java b/sdk/cosmos/microsoft-azure-cosmos/src/main/java/com/azure/data/cosmos/internal/directconnectivity/ResponseUtils.java index e1bdf9f3b3f5e..f7a6f0f9142f2 100644 --- a/sdk/cosmos/microsoft-azure-cosmos/src/main/java/com/azure/data/cosmos/internal/directconnectivity/ResponseUtils.java +++ b/sdk/cosmos/microsoft-azure-cosmos/src/main/java/com/azure/data/cosmos/internal/directconnectivity/ResponseUtils.java @@ -22,7 +22,7 @@ static Mono toStoreResponse(HttpResponse httpClientResponse, Http // for delete we don't expect any body contentObservable = Mono.just(StringUtils.EMPTY); } else { - contentObservable = httpClientResponse.bodyAsString(); + contentObservable = httpClientResponse.bodyAsString().switchIfEmpty(Mono.just(StringUtils.EMPTY)); } return contentObservable.flatMap(content -> {