Skip to content

Commit f5d6d9a

Browse files
committed
Handle client connection errors
Signed-off-by: Paolo Di Tommaso <[email protected]>
1 parent b47f31f commit f5d6d9a

File tree

4 files changed

+48
-7
lines changed

4 files changed

+48
-7
lines changed

app/src/main/java/io/seqera/wave/cli/App.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import io.seqera.wave.api.SubmitContainerTokenRequest;
4949
import io.seqera.wave.api.SubmitContainerTokenResponse;
5050
import io.seqera.wave.cli.exception.BadClientResponseException;
51+
import io.seqera.wave.cli.exception.ClientConnectionException;
5152
import io.seqera.wave.cli.exception.IllegalCliArgumentException;
5253
import io.seqera.wave.cli.json.JsonHelper;
5354
import io.seqera.wave.cli.util.BuildInfo;
@@ -231,7 +232,8 @@ else if( app.inspect ) {
231232
app.run();
232233
}
233234
}
234-
catch (IllegalCliArgumentException | CommandLine.ParameterException | BadClientResponseException e) {
235+
catch (IllegalCliArgumentException | CommandLine.ParameterException | BadClientResponseException |
236+
ClientConnectionException e) {
235237
System.err.println(e.getMessage());
236238
System.exit(1);
237239
}

app/src/main/java/io/seqera/wave/cli/Client.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.util.function.Predicate;
3131

3232
import dev.failsafe.Failsafe;
33+
import dev.failsafe.FailsafeException;
3334
import dev.failsafe.RetryPolicy;
3435
import dev.failsafe.event.EventListener;
3536
import dev.failsafe.event.ExecutionAttemptedEvent;
@@ -42,6 +43,7 @@
4243
import io.seqera.wave.api.SubmitContainerTokenResponse;
4344
import io.seqera.wave.cli.config.RetryOpts;
4445
import io.seqera.wave.cli.exception.BadClientResponseException;
46+
import io.seqera.wave.cli.exception.ClientConnectionException;
4547
import io.seqera.wave.cli.json.JsonHelper;
4648
import org.apache.commons.lang3.StringUtils;
4749
import org.slf4j.Logger;
@@ -103,8 +105,8 @@ ContainerInspectResponse inspect(ContainerInspectRequest request) {
103105
throw new BadClientResponseException(msg);
104106
}
105107
}
106-
catch (IOException e) {
107-
throw new IllegalStateException("Unable to connect Wave service: " + endpoint);
108+
catch (IOException | FailsafeException e) {
109+
throw new ClientConnectionException("Unable to connect Wave service: " + endpoint, e);
108110
}
109111
}
110112

@@ -128,8 +130,8 @@ SubmitContainerTokenResponse submit(SubmitContainerTokenRequest request) {
128130
throw new BadClientResponseException(msg);
129131
}
130132
}
131-
catch (IOException e) {
132-
throw new IllegalStateException("Unable to connect Wave service: " + endpoint);
133+
catch (IOException | FailsafeException e) {
134+
throw new ClientConnectionException("Unable to connect Wave service: " + endpoint, e);
133135
}
134136
}
135137

@@ -231,8 +233,8 @@ ServiceInfo serviceInfo() {
231233
throw new BadClientResponseException(msg);
232234
}
233235
}
234-
catch (IOException e) {
235-
throw new IllegalStateException("Unable to connect Wave service: " + endpoint);
236+
catch (IOException | FailsafeException e) {
237+
throw new ClientConnectionException("Unable to connect Wave service: " + endpoint, e);
236238
}
237239
}
238240
}

app/src/main/java/io/seqera/wave/cli/exception/BadClientResponseException.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
package io.seqera.wave.cli.exception;
1919

2020
/**
21+
* Model a client response http error
22+
*
2123
* @author Paolo Di Tommaso <[email protected]>
2224
*/
2325
public class BadClientResponseException extends RuntimeException {
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2023, Seqera Labs
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
package io.seqera.wave.cli.exception;
19+
20+
/**
21+
* Model a generic client connection exception
22+
*
23+
* @author Paolo Di Tommaso <[email protected]>
24+
*/
25+
public class ClientConnectionException extends RuntimeException {
26+
27+
public ClientConnectionException(String message) {
28+
super(message);
29+
}
30+
31+
public ClientConnectionException(String message, Throwable cause) {
32+
super(message, cause);
33+
}
34+
35+
}

0 commit comments

Comments
 (0)