Skip to content

Commit a7bf83a

Browse files
committed
fix: show actual API message for 403 errors
- Update ResponseHelper to display the actual API error message for 403 responses - Remove misleading 403->NotFoundException conversions across commands: - credentials (delete, update) - runs (delete, cancel, view) - computeenvs (view, delete, update) - studios (view, list, checkpoints, templates, stop, delete, start, add, add-as-new) - Update tests to expect the new 403 error behavior Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: Rob Syme <rob.syme@gmail.com>
1 parent 44914fc commit a7bf83a

File tree

22 files changed

+145
-277
lines changed

22 files changed

+145
-277
lines changed

src/main/java/io/seqera/tower/cli/commands/computeenvs/DeleteCmd.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import io.seqera.tower.ApiException;
2121
import io.seqera.tower.cli.commands.global.WorkspaceOptionalOptions;
22-
import io.seqera.tower.cli.exceptions.ComputeEnvNotFoundException;
2322
import io.seqera.tower.cli.responses.Response;
2423
import io.seqera.tower.cli.responses.computeenvs.ComputeEnvDeleted;
2524
import io.seqera.tower.model.ComputeEnvResponseDto;
@@ -50,15 +49,7 @@ protected Response exec() throws ApiException {
5049
id = computeEnv.getId();
5150
}
5251

53-
try {
54-
computeEnvsApi().deleteComputeEnv(id, wspId);
55-
return new ComputeEnvDeleted(id, workspaceRef(wspId));
56-
} catch (ApiException e) {
57-
if (e.getCode() == 403) {
58-
// Customize the forbidden message
59-
throw new ComputeEnvNotFoundException(id, workspaceRef(wspId));
60-
}
61-
throw e;
62-
}
52+
computeEnvsApi().deleteComputeEnv(id, wspId);
53+
return new ComputeEnvDeleted(id, workspaceRef(wspId));
6354
}
6455
}

src/main/java/io/seqera/tower/cli/commands/computeenvs/UpdateCmd.java

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import io.seqera.tower.ApiException;
2121
import io.seqera.tower.cli.commands.global.WorkspaceOptionalOptions;
22-
import io.seqera.tower.cli.exceptions.ComputeEnvNotFoundException;
2322
import io.seqera.tower.cli.exceptions.InvalidResponseException;
2423
import io.seqera.tower.cli.responses.Response;
2524
import io.seqera.tower.cli.responses.computeenvs.ComputeEnvUpdated;
@@ -70,20 +69,7 @@ protected Response exec() throws ApiException, IOException {
7069

7170
}
7271

73-
private ComputeEnvResponseDto describeCE(ComputeEnvRefOptions computeEnvRefOptions, Long wspId) throws ComputeEnvNotFoundException, ApiException {
74-
try {
75-
return fetchComputeEnv(computeEnvRefOptions, wspId);
76-
77-
} catch (ApiException e) {
78-
if (e.getCode() == 403) {
79-
String ref = computeEnvRefOptions.computeEnv.computeEnvId != null
80-
? computeEnvRefOptions.computeEnv.computeEnvId
81-
: computeEnvRefOptions.computeEnv.computeEnvName;
82-
// Customize the forbidden message
83-
throw new ComputeEnvNotFoundException(ref, workspaceRef(wspId));
84-
}
85-
86-
throw e;
87-
}
72+
private ComputeEnvResponseDto describeCE(ComputeEnvRefOptions computeEnvRefOptions, Long wspId) throws ApiException {
73+
return fetchComputeEnv(computeEnvRefOptions, wspId);
8874
}
8975
}

src/main/java/io/seqera/tower/cli/commands/computeenvs/ViewCmd.java

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import io.seqera.tower.ApiException;
2121
import io.seqera.tower.cli.commands.global.WorkspaceOptionalOptions;
22-
import io.seqera.tower.cli.exceptions.ComputeEnvNotFoundException;
2322
import io.seqera.tower.cli.responses.Response;
2423
import io.seqera.tower.cli.responses.computeenvs.ComputeEnvView;
2524
import io.seqera.tower.model.ComputeEnvResponseDto;
@@ -42,19 +41,8 @@ public class ViewCmd extends AbstractComputeEnvCmd {
4241
protected Response exec() throws ApiException {
4342
Long wspId = workspaceId(workspace.workspace);
4443

45-
try {
46-
ComputeEnvResponseDto computeEnv = fetchComputeEnv(computeEnvRefOptions, wspId);
47-
48-
return new ComputeEnvView(computeEnv.getId(), workspaceRef(wspId), computeEnv, baseWorkspaceUrl(wspId));
49-
} catch (ApiException e) {
50-
if (e.getCode() == 403) {
51-
String ref = computeEnvRefOptions.computeEnv.computeEnvId != null ? computeEnvRefOptions.computeEnv.computeEnvId : computeEnvRefOptions.computeEnv.computeEnvName;
52-
53-
// Customize the forbidden message
54-
throw new ComputeEnvNotFoundException(ref, workspaceRef(wspId));
55-
}
56-
throw e;
57-
}
44+
ComputeEnvResponseDto computeEnv = fetchComputeEnv(computeEnvRefOptions, wspId);
45+
return new ComputeEnvView(computeEnv.getId(), workspaceRef(wspId), computeEnv, baseWorkspaceUrl(wspId));
5846
}
5947

6048
}

src/main/java/io/seqera/tower/cli/commands/credentials/DeleteCmd.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import io.seqera.tower.ApiException;
2121
import io.seqera.tower.cli.commands.global.WorkspaceOptionalOptions;
22-
import io.seqera.tower.cli.exceptions.CredentialsNotFoundException;
2322
import io.seqera.tower.cli.responses.CredentialsDeleted;
2423
import io.seqera.tower.cli.responses.Response;
2524
import io.seqera.tower.model.Credentials;
@@ -50,15 +49,7 @@ protected Response exec() throws ApiException {
5049
id = credentials.getId();
5150
}
5251

53-
try {
54-
deleteCredentialsById(id, wspId);
55-
return new CredentialsDeleted(id, workspaceRef(wspId));
56-
} catch (ApiException e) {
57-
if (e.getCode() == 403) {
58-
// Customize the forbidden message
59-
throw new CredentialsNotFoundException(id, workspaceRef(wspId));
60-
}
61-
throw e;
62-
}
52+
deleteCredentialsById(id, wspId);
53+
return new CredentialsDeleted(id, workspaceRef(wspId));
6354
}
6455
}

src/main/java/io/seqera/tower/cli/commands/credentials/update/AbstractUpdateCmd.java

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import io.seqera.tower.cli.commands.credentials.CredentialsRefOptions;
2323
import io.seqera.tower.cli.commands.credentials.providers.CredentialsProvider;
2424
import io.seqera.tower.cli.commands.global.WorkspaceOptionalOptions;
25-
import io.seqera.tower.cli.exceptions.CredentialsNotFoundException;
2625
import io.seqera.tower.cli.responses.CredentialsUpdated;
2726
import io.seqera.tower.cli.responses.Response;
2827
import io.seqera.tower.model.Credentials;
@@ -48,20 +47,8 @@ public AbstractUpdateCmd() {
4847
protected Response exec() throws ApiException, IOException {
4948
Long wspId = workspaceId(workspace.workspace);
5049

51-
// Check that exists
52-
try {
53-
// DescribeCredentialsResponse response = api().describeCredentials(credentials, wspId);
54-
Credentials credentials = fetchCredentials(credentialsRefOptions, wspId);
55-
return update(credentials, wspId);
56-
} catch (ApiException e) {
57-
if (e.getCode() == 403) {
58-
String ref = credentialsRefOptions.credentialsRef.credentialsId != null ? credentialsRefOptions.credentialsRef.credentialsId : credentialsRefOptions.credentialsRef.credentialsName;
59-
60-
// Customize the forbidden message
61-
throw new CredentialsNotFoundException(ref, workspaceRef(wspId));
62-
}
63-
throw e;
64-
}
50+
Credentials credentials = fetchCredentials(credentialsRefOptions, wspId);
51+
return update(credentials, wspId);
6552
}
6653

6754
protected Response update(Credentials creds, Long wspId) throws ApiException, IOException {

src/main/java/io/seqera/tower/cli/commands/runs/CancelCmd.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import io.seqera.tower.ApiException;
2121
import io.seqera.tower.cli.commands.global.WorkspaceOptionalOptions;
22-
import io.seqera.tower.cli.exceptions.RunNotFoundException;
2322
import io.seqera.tower.cli.responses.Response;
2423
import io.seqera.tower.cli.responses.runs.RunCanceled;
2524
import picocli.CommandLine;
@@ -42,15 +41,7 @@ public class CancelCmd extends AbstractRunsCmd {
4241
protected Response exec() throws ApiException, IOException {
4342
Long wspId = workspaceId(workspace.workspace);
4443

45-
try {
46-
workflowsApi().cancelWorkflow(id, wspId, null, null);
47-
48-
return new RunCanceled(id, workspaceRef(wspId));
49-
} catch (ApiException e) {
50-
if (e.getCode() == 403) {
51-
throw new RunNotFoundException(id, workspaceRef(wspId));
52-
}
53-
throw e;
54-
}
44+
workflowsApi().cancelWorkflow(id, wspId, null, null);
45+
return new RunCanceled(id, workspaceRef(wspId));
5546
}
5647
}

src/main/java/io/seqera/tower/cli/commands/runs/DeleteCmd.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import io.seqera.tower.ApiException;
2121
import io.seqera.tower.cli.commands.global.WorkspaceOptionalOptions;
22-
import io.seqera.tower.cli.exceptions.RunNotFoundException;
2322
import io.seqera.tower.cli.responses.Response;
2423
import io.seqera.tower.cli.responses.runs.RunDeleted;
2524
import picocli.CommandLine;
@@ -45,15 +44,7 @@ public class DeleteCmd extends AbstractRunsCmd {
4544
protected Response exec() throws ApiException, IOException {
4645
Long wspId = workspaceId(workspace.workspace);
4746

48-
try {
49-
workflowsApi().deleteWorkflow(id, wspId, force);
50-
51-
return new RunDeleted(id, workspaceRef(wspId));
52-
} catch (ApiException e) {
53-
if (e.getCode() == 403) {
54-
throw new RunNotFoundException(id, workspaceRef(wspId));
55-
}
56-
throw e;
57-
}
47+
workflowsApi().deleteWorkflow(id, wspId, force);
48+
return new RunDeleted(id, workspaceRef(wspId));
5849
}
5950
}

0 commit comments

Comments
 (0)