Skip to content

Commit bfdffd0

Browse files
authored
[Fix #1737] Calculate communication status error code from cause. (#1739)
Fix #1737 Signed-off-by: Francisco Javier Tirado Sarti <ftirados@ibm.com>
1 parent 5908920 commit bfdffd0

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

‎impl/http/src/main/java/io/serverlessworkflow/impl/executors/http/AbstractRequestExecutor.java‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,13 @@
3131
import jakarta.ws.rs.client.Invocation.Builder;
3232
import jakarta.ws.rs.core.Response;
3333
import jakarta.ws.rs.core.Response.Status.Family;
34+
import java.net.SocketTimeoutException;
3435
import java.net.URI;
36+
import java.net.http.HttpTimeoutException;
3537
import java.util.Optional;
3638
import java.util.concurrent.CompletableFuture;
3739
import java.util.concurrent.ExecutorService;
40+
import java.util.concurrent.TimeoutException;
3841

3942
abstract class AbstractRequestExecutor implements RequestExecutor {
4043

@@ -79,15 +82,27 @@ private WorkflowModel doRequest(
7982
.application()
8083
.modelFactory()
8184
.fromAny(response.readEntity(converter.responseType()));
82-
} catch (ProcessingException | IllegalStateException ex) {
85+
} catch (ProcessingException ex) {
8386
throw new WorkflowException(
84-
WorkflowError.communication(Errors.DATA.status(), task, ex).build(), ex);
87+
WorkflowError.communication(errorCodeFromException(ex.getCause()), task, ex).build(), ex);
8588
} catch (WebApplicationException ex) {
8689
throw new WorkflowException(
8790
WorkflowError.communication(ex.getResponse().getStatus(), task, ex).build(), ex);
8891
}
8992
}
9093

94+
protected int errorCodeFromException(Throwable ex) {
95+
while (ex != null) {
96+
if (ex instanceof TimeoutException
97+
|| ex instanceof SocketTimeoutException
98+
|| ex instanceof HttpTimeoutException) {
99+
return Errors.TIMEOUT.status();
100+
}
101+
ex = ex.getCause();
102+
}
103+
return Errors.COMMUNICATION.status();
104+
}
105+
91106
private void validateStatus(TaskContext task, Response response, HttpModelConverter converter) {
92107
Family statusFamily = response.getStatusInfo().getFamily();
93108
if (statusFamily != SUCCESSFUL && (!this.redirect || statusFamily != REDIRECTION)) {

‎types/src/main/java/io/serverlessworkflow/types/Errors.java‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,8 @@ public String toString() {
8585
}
8686
}
8787

88-
// ---- Standard catalog (defaults are conventional HTTP mappings; override if you prefer) ----
8988
public static final Standard RUNTIME = new Standard("runtime", 500);
90-
public static final Standard COMMUNICATION = new Standard("communication", 502);
89+
public static final Standard COMMUNICATION = new Standard("communication", 500);
9190
public static final Standard AUTHENTICATION = new Standard("authentication", 401);
9291
public static final Standard AUTHORIZATION = new Standard("authorization", 403);
9392
public static final Standard DATA = new Standard("data", 422);

0 commit comments

Comments
 (0)