Skip to content

Commit 66a8b67

Browse files
committed
add exception for example/sdk related issues
1 parent 52951fe commit 66a8b67

File tree

5 files changed

+47
-6
lines changed

5 files changed

+47
-6
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package cloud.stackit.sdk.core.exception;
2+
3+
/**
4+
* Exception thrown when SDK operations fail.
5+
* This includes API calls, network issues, and other SDK-related failures.
6+
*/
7+
public class SdkException extends RuntimeException {
8+
private static final long serialVersionUID = 1L;
9+
10+
/**
11+
* Constructs a new SdkException with the specified detail message.
12+
*
13+
* @param message the detail message
14+
*/
15+
public SdkException(String message) {
16+
super(message);
17+
}
18+
19+
/**
20+
* Constructs a new SdkException with the specified detail message and cause.
21+
*
22+
* @param message the detail message
23+
* @param cause the cause of this exception
24+
*/
25+
public SdkException(String message, Throwable cause) {
26+
super(message, cause);
27+
}
28+
29+
/**
30+
* Constructs a new SdkException with the specified cause.
31+
*
32+
* @param cause the cause of this exception
33+
*/
34+
public SdkException(Throwable cause) {
35+
super(cause);
36+
}
37+
}

examples/authentication/src/main/java/cloud/stackit/sdk/authentication/examples/AuthenticationExample.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import cloud.stackit.sdk.core.config.CoreConfiguration;
44
import cloud.stackit.sdk.core.exception.ApiException;
5+
import cloud.stackit.sdk.core.exception.SdkException;
56
import cloud.stackit.sdk.resourcemanager.api.ResourceManagerApi;
67
import cloud.stackit.sdk.resourcemanager.model.ListOrganizationsResponse;
78
import java.io.File;
@@ -34,7 +35,7 @@ public static void main(String[] args) throws IOException {
3435

3536
System.out.println(response.toString());
3637
} catch (ApiException | IOException e) {
37-
throw new IllegalStateException(e);
38+
throw new SdkException(e);
3839
}
3940

4041
/*
@@ -88,7 +89,7 @@ public static void main(String[] args) throws IOException {
8889

8990
System.out.println(response.toString());
9091
} catch (ApiException | IOException e) {
91-
throw new IllegalStateException(e);
92+
throw new SdkException(e);
9293
}
9394

9495
/*
@@ -125,7 +126,7 @@ public static void main(String[] args) throws IOException {
125126

126127
System.out.println(response.toString());
127128
} catch (ApiException | IOException e) {
128-
throw new IllegalStateException(e);
129+
throw new SdkException(e);
129130
}
130131
}
131132
}

examples/custom-http-client/src/main/java/cloud/stackit/sdk/customhttpclient/examples/CustomHttpClientExample.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import cloud.stackit.sdk.core.KeyFlowAuthenticator;
44
import cloud.stackit.sdk.core.config.CoreConfiguration;
55
import cloud.stackit.sdk.core.exception.ApiException;
6+
import cloud.stackit.sdk.core.exception.SdkException;
67
import cloud.stackit.sdk.iaas.api.IaasApi;
78
import cloud.stackit.sdk.iaas.model.*;
89
import java.io.IOException;
@@ -54,7 +55,7 @@ public static void main(String[] args) throws IOException {
5455
System.out.println("* " + server.getId() + " | " + server.getName());
5556
}
5657
} catch (ApiException e) {
57-
throw new IllegalStateException(e);
58+
throw new SdkException(e);
5859
}
5960
}
6061
}

examples/iaas/src/main/java/cloud/stackit/sdk/iaas/examples/IaaSExample.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cloud.stackit.sdk.iaas.examples;
22

33
import cloud.stackit.sdk.core.exception.ApiException;
4+
import cloud.stackit.sdk.core.exception.SdkException;
45
import cloud.stackit.sdk.iaas.api.IaasApi;
56
import cloud.stackit.sdk.iaas.model.*;
67
import java.io.IOException;
@@ -290,7 +291,7 @@ public static void main(String[] args) throws IOException {
290291
System.out.println("Deleted network: " + newNetwork.getNetworkId());
291292

292293
} catch (ApiException | InterruptedException e) {
293-
throw new IllegalStateException(e);
294+
throw new SdkException(e);
294295
}
295296
}
296297
}

examples/resourcemanager/src/main/java/cloud/stackit/sdk/resourcemanager/examples/ResourcemanagerExample.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cloud.stackit.sdk.resourcemanager.examples;
22

33
import cloud.stackit.sdk.core.exception.ApiException;
4+
import cloud.stackit.sdk.core.exception.SdkException;
45
import cloud.stackit.sdk.resourcemanager.api.ResourceManagerApi;
56
import cloud.stackit.sdk.resourcemanager.model.CreateFolderPayload;
67
import cloud.stackit.sdk.resourcemanager.model.CreateProjectPayload;
@@ -112,7 +113,7 @@ public static void main(String[] args) throws IOException {
112113
/* delete folder */
113114
resourceManagerApi.deleteFolder(folder.getContainerId(), true);
114115
} catch (ApiException e) {
115-
throw new IllegalStateException(e);
116+
throw new SdkException(e);
116117
}
117118
}
118119
}

0 commit comments

Comments
 (0)