Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix usage of new ingress exception constructor #367

Merged
merged 1 commit into from
Aug 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading