Search in sources :

Example 1 with NoSuchIndexException

use of org.springframework.data.elasticsearch.NoSuchIndexException in project spring-data-elasticsearch by spring-projects.

the class ElasticsearchExceptionTranslator method translateExceptionIfPossible.

@Override
public DataAccessException translateExceptionIfPossible(RuntimeException ex) {
    if (isSeqNoConflict(ex)) {
        return new OptimisticLockingFailureException("Cannot index a document due to seq_no+primary_term conflict", ex);
    }
    if (ex instanceof ElasticsearchException) {
        ElasticsearchException elasticsearchException = (ElasticsearchException) ex;
        if (!indexAvailable(elasticsearchException)) {
            return new NoSuchIndexException(ObjectUtils.nullSafeToString(elasticsearchException.getMetadata("es.index")), ex);
        }
        if (elasticsearchException instanceof ElasticsearchStatusException) {
            ElasticsearchStatusException elasticsearchStatusException = (ElasticsearchStatusException) elasticsearchException;
            return new RestStatusException(elasticsearchStatusException.status().getStatus(), elasticsearchStatusException.getMessage(), elasticsearchStatusException);
        }
        return new UncategorizedElasticsearchException(ex.getMessage(), ex);
    }
    if (ex instanceof RestStatusException) {
        RestStatusException restStatusException = (RestStatusException) ex;
        Throwable cause = restStatusException.getCause();
        if (cause instanceof ElasticsearchException) {
            ElasticsearchException elasticsearchException = (ElasticsearchException) cause;
            if (!indexAvailable(elasticsearchException)) {
                return new NoSuchIndexException(ObjectUtils.nullSafeToString(elasticsearchException.getMetadata("es.index")), ex);
            }
        }
    }
    if (ex instanceof ValidationException) {
        return new DataIntegrityViolationException(ex.getMessage(), ex);
    }
    Throwable cause = ex.getCause();
    if (cause instanceof IOException) {
        return new DataAccessResourceFailureException(ex.getMessage(), ex);
    }
    return null;
}
Also used : OptimisticLockingFailureException(org.springframework.dao.OptimisticLockingFailureException) ValidationException(org.elasticsearch.common.ValidationException) DataAccessResourceFailureException(org.springframework.dao.DataAccessResourceFailureException) NoSuchIndexException(org.springframework.data.elasticsearch.NoSuchIndexException) UncategorizedElasticsearchException(org.springframework.data.elasticsearch.UncategorizedElasticsearchException) ElasticsearchException(org.elasticsearch.ElasticsearchException) UncategorizedElasticsearchException(org.springframework.data.elasticsearch.UncategorizedElasticsearchException) IOException(java.io.IOException) RestStatusException(org.springframework.data.elasticsearch.RestStatusException) ElasticsearchStatusException(org.elasticsearch.ElasticsearchStatusException) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException)

Aggregations

IOException (java.io.IOException)1 ElasticsearchException (org.elasticsearch.ElasticsearchException)1 ElasticsearchStatusException (org.elasticsearch.ElasticsearchStatusException)1 ValidationException (org.elasticsearch.common.ValidationException)1 DataAccessResourceFailureException (org.springframework.dao.DataAccessResourceFailureException)1 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)1 OptimisticLockingFailureException (org.springframework.dao.OptimisticLockingFailureException)1 NoSuchIndexException (org.springframework.data.elasticsearch.NoSuchIndexException)1 RestStatusException (org.springframework.data.elasticsearch.RestStatusException)1 UncategorizedElasticsearchException (org.springframework.data.elasticsearch.UncategorizedElasticsearchException)1