mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-06-21 11:32:12 +00:00
Fix NPE in ElasticsearchExceptionTranslator.
Original Pull Request #2389 Closes #2388 (cherry picked from commit 9446d726bc5a90321d416e43af41f908f6191ab2)
This commit is contained in:
parent
8fe04172f6
commit
4bf1435555
@ -74,13 +74,15 @@ public class ElasticsearchExceptionTranslator implements PersistenceExceptionTra
|
||||
if (ex instanceof ElasticsearchException elasticsearchException) {
|
||||
|
||||
ErrorResponse response = elasticsearchException.response();
|
||||
var errorType = response.error().type();
|
||||
var errorReason = response.error().reason() != null ? response.error().reason() : "undefined reason";
|
||||
|
||||
if (response.status() == 404 && "index_not_found_exception".equals(response.error().type())) {
|
||||
if (response.status() == 404 && "index_not_found_exception".equals(errorType)) {
|
||||
|
||||
// noinspection RegExpRedundantEscape
|
||||
Pattern pattern = Pattern.compile(".*no such index \\[(.*)\\]");
|
||||
String index = "";
|
||||
Matcher matcher = pattern.matcher(response.error().reason());
|
||||
Matcher matcher = pattern.matcher(errorReason);
|
||||
if (matcher.matches()) {
|
||||
index = matcher.group(1);
|
||||
}
|
||||
@ -88,8 +90,8 @@ public class ElasticsearchExceptionTranslator implements PersistenceExceptionTra
|
||||
}
|
||||
String body = JsonUtils.toJson(response, jsonpMapper);
|
||||
|
||||
if (response.error().type().contains("validation_exception")) {
|
||||
return new DataIntegrityViolationException(response.error().reason());
|
||||
if (errorType != null && errorType.contains("validation_exception")) {
|
||||
return new DataIntegrityViolationException(errorReason);
|
||||
}
|
||||
|
||||
return new UncategorizedElasticsearchException(ex.getMessage(), response.status(), body, ex);
|
||||
|
Loading…
x
Reference in New Issue
Block a user