Skip to content

Commit

Permalink
Remove unused methods in Result
Browse files Browse the repository at this point in the history
  • Loading branch information
antas-marcin committed Nov 26, 2024
1 parent 0af97b8 commit 3109a38
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
16 changes: 7 additions & 9 deletions src/main/java/io/weaviate/client/base/Result.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
@ToString
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
public class Result<T> {
int statusCode;
T result;
WeaviateError error;

Expand All @@ -23,7 +22,6 @@ public Result(Response<T> response) {
}

public Result(int statusCode, T body, WeaviateErrorResponse errors) {
this.statusCode = statusCode;
if (errors != null && errors.getError() != null) {
List<WeaviateErrorMessage> items = errors.getError().stream().filter(Objects::nonNull).collect(Collectors.toList());
this.error = new WeaviateError(statusCode, items);
Expand All @@ -37,17 +35,17 @@ public Result(int statusCode, T body, WeaviateErrorResponse errors) {
}
}

public boolean hasErrors() {
return this.error != null;
}

/**
* Copy the Result object with a null body, preserving only the status code and the error message.
*
* @param <NULL> Would-be response type. It's required for type safety, but can be anything since the body is always set to null.
*
* @param <C> Would-be response type. It's required for type safety, but can be anything since the body is always set to null.
* @return A copy of this Result.
*/
public <NULL> Result<NULL> toErrorResult() {
public <C> Result<C> toErrorResult() {
return new Result<>(this.error.getStatusCode(), null, WeaviateErrorResponse.builder().error(this.error.getMessages()).build());
}

public boolean hasErrors() {
return this.error != null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public Future<Result<ShardStatus[]>> run(FutureCallback<Result<ShardStatus[]>> c
try {
Result<Shard[]> shards = this.shardsGetter.withClassName(this.className).run().get();
if (shards.hasErrors()) {
return shards.<ShardStatus[]>toErrorResult();
return shards.toErrorResult();
}

List<ShardStatus> shardStatuses = new ArrayList<>();
Expand All @@ -75,12 +75,12 @@ public Future<Result<ShardStatus[]>> run(FutureCallback<Result<ShardStatus[]>> c
.withShardName(shard.getName())
.withStatus(this.status).run().get();
if (update.hasErrors()) {
return update.<ShardStatus[]>toErrorResult();
return update.toErrorResult();
}
shardStatuses.add(update.getResult());
}

return new Result<ShardStatus[]>(HttpStatus.SC_OK, shardStatuses.toArray(new ShardStatus[shardStatuses.size()]), null);
return new Result<>(HttpStatus.SC_OK, shardStatuses.toArray(new ShardStatus[shardStatuses.size()]), null);
} catch (ExecutionException | InterruptedException e) {
throw new CompletionException(e);
}
Expand Down

0 comments on commit 3109a38

Please sign in to comment.