Skip to content

Commit

Permalink
Fix usage of new ingress exception constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
slinkydeveloper committed Aug 7, 2024
1 parent d10a136 commit 8ca7669
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions sdk-common/src/main/java/dev/restate/sdk/client/DefaultClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public <Req, Res> CompletableFuture<Res> callAsync(
.handle(
(response, throwable) -> {
if (throwable != null) {
throw new IngressException("Error when executing the request", response, throwable);
throw new IngressException("Error when executing the request", request, throwable);
}

if (response.statusCode() >= 300) {
Expand All @@ -81,7 +81,7 @@ public <Req> CompletableFuture<SendResponse> sendAsync(
.handle(
(response, throwable) -> {
if (throwable != null) {
throw new IngressException("Error when executing the request", response, throwable);
throw new IngressException("Error when executing the request", request, throwable);
}
if (response.statusCode() >= 300) {
handleNonSuccessResponse(response);
Expand Down Expand Up @@ -114,9 +114,10 @@ public <Req> CompletableFuture<SendResponse> sendAsync(
@Override
public AwakeableHandle awakeableHandle(String id) {
return new AwakeableHandle() {
private Void handleVoidResponse(HttpResponse<byte[]> response, Throwable throwable) {
private Void handleVoidResponse(
HttpRequest request, HttpResponse<byte[]> response, Throwable throwable) {
if (throwable != null) {
throw new IngressException("Error when executing the request", response, throwable);
throw new IngressException("Error when executing the request", request, throwable);
}

if (response.statusCode() >= 300) {
Expand Down Expand Up @@ -145,7 +146,7 @@ public <T> CompletableFuture<Void> resolveAsync(
.build();
return httpClient
.sendAsync(request, HttpResponse.BodyHandlers.ofByteArray())
.handle(this::handleVoidResponse);
.handle((res, t) -> this.handleVoidResponse(request, res, t));
}

@Override
Expand All @@ -164,7 +165,7 @@ public CompletableFuture<Void> rejectAsync(String reason, RequestOptions options
HttpRequest request = reqBuilder.POST(HttpRequest.BodyPublishers.ofString(reason)).build();
return httpClient
.sendAsync(request, HttpResponse.BodyHandlers.ofByteArray())
.handle(this::handleVoidResponse);
.handle((res, t) -> this.handleVoidResponse(request, res, t));
}
};
}
Expand All @@ -188,7 +189,7 @@ public CompletableFuture<Res> attachAsync(RequestOptions options) {
HttpRequest request = reqBuilder.GET().build();
return httpClient
.sendAsync(request, HttpResponse.BodyHandlers.ofByteArray())
.handle(handleAttachResponse(resSerde));
.handle(handleAttachResponse(request, resSerde));
}

@Override
Expand All @@ -202,7 +203,7 @@ public CompletableFuture<Output<Res>> getOutputAsync(RequestOptions options) {
HttpRequest request = reqBuilder.GET().build();
return httpClient
.sendAsync(request, HttpResponse.BodyHandlers.ofByteArray())
.handle(handleGetOutputResponse(resSerde));
.handle(handleGetOutputResponse(request, resSerde));
}
};
}
Expand All @@ -227,7 +228,7 @@ public CompletableFuture<Res> attachAsync(RequestOptions options) {
HttpRequest request = reqBuilder.GET().build();
return httpClient
.sendAsync(request, HttpResponse.BodyHandlers.ofByteArray())
.handle(handleAttachResponse(resSerde));
.handle(handleAttachResponse(request, resSerde));
}

@Override
Expand All @@ -246,7 +247,7 @@ public CompletableFuture<Output<Res>> getOutputAsync(RequestOptions options) {
HttpRequest request = reqBuilder.GET().build();
return httpClient
.sendAsync(request, HttpResponse.BodyHandlers.ofByteArray())
.handle(handleGetOutputResponse(resSerde));
.handle(handleGetOutputResponse(request, resSerde));
}
};
}
Expand All @@ -272,7 +273,7 @@ public CompletableFuture<Res> attachAsync(RequestOptions options) {
HttpRequest request = reqBuilder.GET().build();
return httpClient
.sendAsync(request, HttpResponse.BodyHandlers.ofByteArray())
.handle(handleAttachResponse(resSerde));
.handle(handleAttachResponse(request, resSerde));
}

@Override
Expand All @@ -292,17 +293,17 @@ public CompletableFuture<Output<Res>> getOutputAsync(RequestOptions options) {
HttpRequest request = reqBuilder.GET().build();
return httpClient
.sendAsync(request, HttpResponse.BodyHandlers.ofByteArray())
.handle(handleGetOutputResponse(resSerde));
.handle(handleGetOutputResponse(request, resSerde));
}
};
}

private <Res> @NotNull
BiFunction<HttpResponse<byte[]>, Throwable, Output<Res>> handleGetOutputResponse(
Serde<Res> resSerde) {
HttpRequest request, Serde<Res> resSerde) {
return (response, throwable) -> {
if (throwable != null) {
throw new IngressException("Error when executing the request", response, throwable);
throw new IngressException("Error when executing the request", request, throwable);
}

if (response.statusCode() == 470) {
Expand All @@ -322,10 +323,10 @@ BiFunction<HttpResponse<byte[]>, Throwable, Output<Res>> handleGetOutputResponse
}

private <Res> @NotNull BiFunction<HttpResponse<byte[]>, Throwable, Res> handleAttachResponse(
Serde<Res> resSerde) {
HttpRequest request, Serde<Res> resSerde) {
return (response, throwable) -> {
if (throwable != null) {
throw new IngressException("Error when executing the request", response, throwable);
throw new IngressException("Error when executing the request", request, throwable);
}

if (response.statusCode() >= 300) {
Expand Down

0 comments on commit 8ca7669

Please sign in to comment.