diff --git a/core/app/datasource/src/main/java/io/openk9/datasource/web/DataIndexResource.java b/core/app/datasource/src/main/java/io/openk9/datasource/web/DataIndexResource.java index b05c106fa..acf1d156d 100644 --- a/core/app/datasource/src/main/java/io/openk9/datasource/web/DataIndexResource.java +++ b/core/app/datasource/src/main/java/io/openk9/datasource/web/DataIndexResource.java @@ -28,6 +28,7 @@ import io.smallrye.mutiny.Uni; import io.smallrye.mutiny.unchecked.Unchecked; import io.vertx.core.json.Json; +import io.vertx.core.json.JsonObject; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; @@ -41,6 +42,7 @@ import org.opensearch.cluster.metadata.Template; import org.opensearch.common.compress.CompressedXContent; import org.opensearch.common.settings.Settings; +import org.opensearch.indices.InvalidIndexTemplateException; import java.time.OffsetDateTime; import java.util.LinkedHashSet; @@ -52,9 +54,11 @@ import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.Root; +import javax.ws.rs.BadRequestException; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.PathParam; +import javax.ws.rs.core.Response; @CircuitBreaker @Path("/v1/data-index") @@ -255,6 +259,16 @@ public Uni createDataIndexFromDocTypes( sink.complete(null); } catch (Exception e) { + if (e instanceof InvalidIndexTemplateException ose) { + sink.fail(new BadRequestException(Response + .status(400) + .entity(JsonObject.of( + "details", + ose.getDetailedMessage() + )) + .build())); + return; + } sink.fail(e); }