From 54fdaffe7e43ae3f37e0b92356ee7283a113da3c Mon Sep 17 00:00:00 2001 From: skyflow-bharti Date: Mon, 26 Oct 2026 15:14:17 +0530 Subject: [PATCH 1/4] SK-3175 fix sdk response parsing issue --- .../java/com/skyflow/BaseVaultClient.java | 26 ++++++- .../BaseVaultClientErrorBodyTests.java | 69 +++++++++++++++++++ 2 files changed, 92 insertions(+), 3 deletions(-) create mode 100644 common/src/test/java/com/skyflow/BaseVaultClientErrorBodyTests.java diff --git a/common/src/main/java/com/skyflow/BaseVaultClient.java b/common/src/main/java/com/skyflow/BaseVaultClient.java index 973510d7..9cec36c2 100644 --- a/common/src/main/java/com/skyflow/BaseVaultClient.java +++ b/common/src/main/java/com/skyflow/BaseVaultClient.java @@ -1,12 +1,12 @@ package com.skyflow; -import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.skyflow.config.BaseCredentials; import com.skyflow.config.BaseVaultConfig; import com.skyflow.errors.ErrorCode; import com.skyflow.errors.BaseErrorMessage; import com.skyflow.errors.SkyflowException; +import com.skyflow.generated.detect.rest.core.ObjectMappers; import com.skyflow.logs.ErrorLogs; import com.skyflow.logs.InfoLogs; import com.skyflow.serviceaccount.util.Token; @@ -108,7 +108,27 @@ protected static SkyflowException wrapApiException(int statusCode, Throwable cau Map> headers, Object responseBody, ErrorLogs errorLog) { LogUtil.printErrorLog(errorLog.getLog()); - Gson gson = new GsonBuilder().serializeNulls().create(); - return new SkyflowException(statusCode, cause, headers, gson.toJson(responseBody)); + return new SkyflowException(statusCode, cause, headers, errorBodyAsJson(responseBody)); + } + + /** + * Serialises an API error body back to the JSON the server sent. The generated clients hand us either a + * plain {@code Map} or a typed {@code ErrorResponse}; the typed form carries Jackson annotations for the wire + * names ({@code grpc_code}, {@code http_status}) and {@code Optional} fields, so Jackson must do the + * serialisation. Gson would emit the Java field names, which {@link SkyflowException} cannot parse, and + * fails outright on {@code Optional} under JDK 17+. + */ + static String errorBodyAsJson(Object responseBody) { + if (responseBody == null) { + return null; + } + if (responseBody instanceof String) { + return (String) responseBody; + } + try { + return ObjectMappers.JSON_MAPPER.writeValueAsString(responseBody); + } catch (Exception e) { + return new GsonBuilder().serializeNulls().create().toJson(responseBody); + } } } diff --git a/common/src/test/java/com/skyflow/BaseVaultClientErrorBodyTests.java b/common/src/test/java/com/skyflow/BaseVaultClientErrorBodyTests.java new file mode 100644 index 00000000..f016a6f3 --- /dev/null +++ b/common/src/test/java/com/skyflow/BaseVaultClientErrorBodyTests.java @@ -0,0 +1,69 @@ +package com.skyflow; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.skyflow.errors.SkyflowException; +import com.skyflow.logs.ErrorLogs; +import org.junit.Assert; +import org.junit.Test; + +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +public class BaseVaultClientErrorBodyTests { + + /** Shape of the Fern-generated ErrorResponse: wire names via @JsonProperty, Optional fields. */ + public static final class TypedError { + @JsonProperty("grpc_code") public Optional grpcCode = Optional.of(5); + @JsonProperty("http_code") public Optional httpCode = Optional.of(404); + @JsonProperty("http_status") public Optional httpStatus = Optional.of("Not Found"); + @JsonProperty("message") public Optional message = Optional.of("Detokenization failed. Token x is invalid."); + @JsonProperty("details") public Optional> details = Optional.of(Collections.emptyList()); + } + + public static final class TypedErrorResponse { + @JsonProperty("error") public TypedError error = new TypedError(); + } + + private static Map> headers() { + Map> h = new HashMap<>(); + h.put("x-request-id", Collections.singletonList("req-1")); + return h; + } + + @Test + public void typedErrorBodyIsParsedIntoTheExceptionFields() { + SkyflowException e = BaseVaultClient.wrapApiException(404, new RuntimeException("boom"), headers(), + new TypedErrorResponse(), ErrorLogs.DETOKENIZE_REQUEST_REJECTED); + Assert.assertEquals(404, e.getHttpCode()); + Assert.assertEquals("Not Found", e.getHttpStatus()); + Assert.assertEquals(Integer.valueOf(5), e.getGrpcCode()); + Assert.assertEquals("Detokenization failed. Token x is invalid.", e.getMessage()); + Assert.assertEquals("req-1", e.getRequestId()); + Assert.assertEquals(0, e.getDetails().size()); + } + + @Test + public void mapErrorBodyStillWorks() { + Map error = new HashMap<>(); + error.put("grpc_code", 3); + error.put("http_status", "Bad Request"); + error.put("message", "Insert failed. Column cv is invalid."); + error.put("details", Collections.emptyList()); + Map body = new HashMap<>(); + body.put("error", error); + SkyflowException e = BaseVaultClient.wrapApiException(400, new RuntimeException("boom"), headers(), body, + ErrorLogs.INSERT_RECORDS_REJECTED); + Assert.assertEquals("Bad Request", e.getHttpStatus()); + Assert.assertEquals(Integer.valueOf(3), e.getGrpcCode()); + Assert.assertEquals("Insert failed. Column cv is invalid.", e.getMessage()); + } + + @Test + public void nullAndStringBodiesDoNotThrow() { + Assert.assertNull(BaseVaultClient.errorBodyAsJson(null)); + Assert.assertEquals("{\"error\":{}}", BaseVaultClient.errorBodyAsJson("{\"error\":{}}")); + } +} From d5fceff54c2fec2f2b3cab572700f90106bfe1c4 Mon Sep 17 00:00:00 2001 From: skyflow-bharti Date: Mon, 26 Oct 2026 09:45:15 +0000 Subject: [PATCH 2/4] [AUTOMATED] Private Release 1.2.0-dev-54fdaffe --- flowvault/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flowvault/pom.xml b/flowvault/pom.xml index 43a57f15..eb34ebff 100644 --- a/flowvault/pom.xml +++ b/flowvault/pom.xml @@ -12,7 +12,7 @@ skyflow-flowvault-java - 1.2.0-dev.225f34ec + 1.2.0-dev.54fdaffe jar ${project.groupId}:${project.artifactId} Skyflow FlowVault SDK for the Java programming language From 3657b62df4cd75b89f44cf6e2123e6723b57260b Mon Sep 17 00:00:00 2001 From: skyflow-bharti Date: Mon, 26 Oct 2026 15:22:15 +0530 Subject: [PATCH 3/4] SK-3175 fix spellcheck --- common/src/main/java/com/skyflow/BaseVaultClient.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/com/skyflow/BaseVaultClient.java b/common/src/main/java/com/skyflow/BaseVaultClient.java index 9cec36c2..ba53d00e 100644 --- a/common/src/main/java/com/skyflow/BaseVaultClient.java +++ b/common/src/main/java/com/skyflow/BaseVaultClient.java @@ -112,10 +112,10 @@ protected static SkyflowException wrapApiException(int statusCode, Throwable cau } /** - * Serialises an API error body back to the JSON the server sent. The generated clients hand us either a + * Serializes an API error body back to the JSON the server sent. The generated clients hand us either a * plain {@code Map} or a typed {@code ErrorResponse}; the typed form carries Jackson annotations for the wire * names ({@code grpc_code}, {@code http_status}) and {@code Optional} fields, so Jackson must do the - * serialisation. Gson would emit the Java field names, which {@link SkyflowException} cannot parse, and + * serialization. Gson would emit the Java field names, which {@link SkyflowException} cannot parse, and * fails outright on {@code Optional} under JDK 17+. */ static String errorBodyAsJson(Object responseBody) { From a03e44193abe88a9f329083f6b3ab442b23382fb Mon Sep 17 00:00:00 2001 From: skyflow-bharti Date: Mon, 26 Oct 2026 09:52:41 +0000 Subject: [PATCH 4/4] [AUTOMATED] Private Release 1.2.0-dev-3657b62d --- flowvault/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flowvault/pom.xml b/flowvault/pom.xml index eb34ebff..f66c66c2 100644 --- a/flowvault/pom.xml +++ b/flowvault/pom.xml @@ -12,7 +12,7 @@ skyflow-flowvault-java - 1.2.0-dev.54fdaffe + 1.2.0-dev.3657b62d jar ${project.groupId}:${project.artifactId} Skyflow FlowVault SDK for the Java programming language