Skip to content

Commit

Permalink
issue #1013: adds invalid template exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mrk-vi committed Aug 27, 2024
1 parent 190358b commit b11fb3e
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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")
Expand Down Expand Up @@ -255,6 +259,16 @@ public Uni<DataIndex> 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);
}

Expand Down

0 comments on commit b11fb3e

Please sign in to comment.