Skip to content

Commit 8118713

Browse files
committed
DATAES-822 - Convert Reactive Server Exceptions to ElasticsearchStatusException.
1 parent cea8c93 commit 8118713

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/main/java/org/springframework/data/elasticsearch/client/reactive/DefaultReactiveElasticsearchClient.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@
9494
import org.elasticsearch.search.SearchHits;
9595
import org.elasticsearch.search.aggregations.Aggregation;
9696
import org.reactivestreams.Publisher;
97-
9897
import org.springframework.data.elasticsearch.client.ClientConfiguration;
9998
import org.springframework.data.elasticsearch.client.ClientLogger;
10099
import org.springframework.data.elasticsearch.client.ElasticsearchHost;
@@ -113,7 +112,6 @@
113112
import org.springframework.util.Assert;
114113
import org.springframework.util.ObjectUtils;
115114
import org.springframework.util.ReflectionUtils;
116-
import org.springframework.web.client.HttpServerErrorException;
117115
import org.springframework.web.reactive.function.BodyExtractors;
118116
import org.springframework.web.reactive.function.client.ClientRequest;
119117
import org.springframework.web.reactive.function.client.ClientResponse;
@@ -806,9 +804,10 @@ private static XContentParser createParser(String mediaType, String content) thr
806804

807805
private <T> Publisher<? extends T> handleServerError(Request request, ClientResponse response) {
808806

809-
return Mono.error(
810-
new HttpServerErrorException(response.statusCode(), String.format("%s request to %s returned error code %s.",
811-
request.getMethod(), request.getEndpoint(), response.statusCode().value())));
807+
RestStatus status = RestStatus.fromCode(response.statusCode().value());
808+
809+
return Mono.error(new ElasticsearchStatusException(String.format("%s request to %s returned error code %s.",
810+
request.getMethod(), request.getEndpoint(), response.statusCode().value()), status));
812811
}
813812

814813
private <T> Publisher<? extends T> handleClientError(String logId, Request request, ClientResponse response,
@@ -828,8 +827,7 @@ private <T> Publisher<? extends T> handleClientError(String logId, Request reque
828827
return Mono.error(new ElasticsearchStatusException(sb.toString(), status, exception));
829828
}
830829
} catch (Exception e) {
831-
return Mono
832-
.error(new ElasticsearchStatusException(content, status));
830+
return Mono.error(new ElasticsearchStatusException(content, status));
833831
}
834832
return Mono.just(content);
835833
}).doOnNext(it -> ClientLogger.logResponse(logId, response.statusCode(), it)) //

0 commit comments

Comments
 (0)