99import java .util .List ;
1010import java .util .Map ;
1111
12+ /**
13+ * Exception thrown by all Skyflow SDK operations.
14+ *
15+ * <p>There are two broad categories of errors:
16+ *
17+ * <ul>
18+ * <li><b>Validation errors</b> — caught before any network call is made (e.g. missing table,
19+ * empty token list). These always have {@code httpCode = 400} and an empty
20+ * {@link #getDetails()} array. {@link #getRequestId()} and {@link #getGrpcCode()} are
21+ * {@code null}.
22+ * <li><b>API errors</b> — returned by the Skyflow server. The HTTP status code, gRPC code,
23+ * human-readable status string, error message, and request ID are all parsed from the
24+ * response and available via the corresponding getters.
25+ * </ul>
26+ *
27+ * <p>Typical error-handling pattern:
28+ * <pre>{@code
29+ * try {
30+ * response = vault.insert(request);
31+ * } catch (SkyflowException e) {
32+ * System.err.println("HTTP " + e.getHttpCode() + " — " + e.getMessage());
33+ * if (e.getRequestId() != null) {
34+ * System.err.println("Request ID: " + e.getRequestId());
35+ * }
36+ * }
37+ * }</pre>
38+ */
1239public class SkyflowException extends Exception {
1340 private String requestId ;
1441 private Integer grpcCode ;
@@ -33,6 +60,11 @@ public SkyflowException(String message, Throwable cause) {
3360 this .message = message ;
3461 }
3562
63+ /**
64+ * Constructs a validation error with a fixed HTTP 400 status.
65+ * {@link #getDetails()} returns an empty array; {@link #getRequestId()} and
66+ * {@link #getGrpcCode()} return {@code null}.
67+ */
3668 public SkyflowException (int code , String message ) {
3769 super (message );
3870 this .httpCode = code ;
@@ -41,6 +73,13 @@ public SkyflowException(int code, String message) {
4173 this .details = new JsonArray ();
4274 }
4375
76+ /**
77+ * Constructs an API error from an HTTP response.
78+ * Parses the JSON error body to populate {@link #getMessage()}, {@link #getGrpcCode()},
79+ * {@link #getHttpStatus()}, and {@link #getDetails()}. The request ID is read from the
80+ * {@code x-request-id} response header. If the body cannot be parsed, falls back to the
81+ * raw body string as the message.
82+ */
4483 public SkyflowException (int httpCode , Throwable cause , Map <String , List <String >> responseHeaders , String responseBody ) {
4584 super (cause );
4685 this .httpCode = httpCode > 0 ? httpCode : 400 ;
@@ -65,6 +104,10 @@ private void setResponseBody(String responseBody, Map<String, List<String>> resp
65104 }
66105 }
67106
107+ /**
108+ * Returns the {@code x-request-id} from the server response, useful for support escalations.
109+ * {@code null} for validation errors that never reached the server.
110+ */
68111 public String getRequestId () {
69112 return requestId ;
70113 }
@@ -89,10 +132,20 @@ private void setHttpStatus() {
89132 this .httpStatus = statusElement == null ? null : statusElement .getAsString ();
90133 }
91134
135+ /**
136+ * Returns the HTTP status code (e.g. 400, 404, 500).
137+ * Defaults to 400 when the server returned a non-positive code, and 0 when the
138+ * exception carries no HTTP code at all (e.g. it wraps a local failure).
139+ */
92140 public int getHttpCode () {
93141 return httpCode == null ? 0 : httpCode ;
94142 }
95143
144+ /**
145+ * Returns additional error details from the server response, or an empty array for
146+ * validation errors. Never {@code null} for validation errors; may be {@code null} for
147+ * API errors whose response body contained no {@code details} field.
148+ */
96149 public JsonArray getDetails () {
97150 return details ;
98151 }
@@ -112,10 +165,18 @@ private void setDetails(Map<String, List<String>> responseHeaders) {
112165 }
113166 }
114167
168+ /**
169+ * Returns the gRPC status code from the server response.
170+ * {@code null} for validation errors and API responses that omit this field.
171+ */
115172 public Integer getGrpcCode () {
116173 return grpcCode ;
117174 }
118175
176+ /**
177+ * Returns the human-readable HTTP status string from the server response (e.g.
178+ * {@code "Bad Request"}, {@code "Not Found"}).
179+ */
119180 public String getHttpStatus () {
120181 return httpStatus ;
121182 }
0 commit comments