Skip to content

Commit

Permalink
ISPN-16410 Capture an exception if the put schema fails
Browse files Browse the repository at this point in the history
  • Loading branch information
karesti authored and tristantarrant committed Aug 21, 2024
1 parent d9dada3 commit ca218fe
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.infinispan.query.remote.impl.ProtobufMetadataManagerImpl;
import org.infinispan.rest.InvocationHelper;
import org.infinispan.rest.NettyRestResponse;
import org.infinispan.rest.RestRequestHandler;
import org.infinispan.rest.cachemanager.RestCacheManager;
import org.infinispan.rest.framework.ContentSource;
import org.infinispan.rest.framework.ResourceHandler;
Expand Down Expand Up @@ -113,16 +114,25 @@ private CompletionStage<RestResponse> createOrReplace(RestRequest request, boole

CompletableFuture<Object> putSchema;
if (create) {
putSchema = cache.putIfAbsentAsync(schemaName, contents.asString()).thenApply(result -> {
if (result == null) {
putSchema = cache.putIfAbsentAsync(schemaName, contents.asString()).whenComplete((result, ex) -> {
if (ex != null) {
builder.status(HttpResponseStatus.INTERNAL_SERVER_ERROR).entity(RestRequestHandler.filterCause(ex));
} else if (result == null) {
builder.status(HttpResponseStatus.CREATED);
} else {
builder.status(HttpResponseStatus.CONFLICT);
}
return result;
});
} else {
putSchema = cache.putAsync(schemaName, contents.asString()).thenApply(result -> builder.status(HttpResponseStatus.OK));
putSchema = cache.putAsync(schemaName, contents.asString())
.whenComplete((result, ex) -> {
if (ex == null) {
builder.status(HttpResponseStatus.OK);
} else {
builder.status(HttpResponseStatus.INTERNAL_SERVER_ERROR)
.entity(RestRequestHandler.filterCause(ex));
}
});
}

return putSchema.thenCompose(r -> {
Expand Down

0 comments on commit ca218fe

Please sign in to comment.