Skip to content

Commit

Permalink
Return empty string on empty content response from backend (#7347)
Browse files Browse the repository at this point in the history
  • Loading branch information
kushagraThapar authored Jan 11, 2020
1 parent 574f7bc commit 409efc5
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class ErrorUtils {
private static final Logger logger = LoggerFactory.getLogger(ErrorUtils.class);

static Mono<String> getErrorResponseAsync(HttpResponse responseMessage, HttpRequest request) {
Mono<String> responseAsString = responseMessage.bodyAsString();
Mono<String> responseAsString = responseMessage.bodyAsString().switchIfEmpty(Mono.just(StringUtils.EMPTY));
if (request.httpMethod() == HttpMethod.DELETE) {
return Mono.just(StringUtils.EMPTY);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -31,7 +32,7 @@ static Mono<RxDocumentServiceResponse> parseResponseAsync(Mono<HttpResponse> htt
}

private static Mono<CosmosClientException> createDocumentClientException(HttpResponse httpResponse) {
Mono<String> readStream = httpResponse.bodyAsString();
Mono<String> readStream = httpResponse.bodyAsString().switchIfEmpty(Mono.just(StringUtils.EMPTY));

return readStream.map(body -> {
CosmosError cosmosError = BridgeInternal.createCosmosError(body);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ static Mono<StoreResponse> 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 -> {
Expand Down

0 comments on commit 409efc5

Please sign in to comment.