From 760869b369f580847f5c65af04e5cd562f6c39b3 Mon Sep 17 00:00:00 2001 From: Costin Chiulan Date: Tue, 6 Aug 2024 11:09:03 +0300 Subject: [PATCH] [ISSUE] Error parsing Databricks Error #260 --- .../com/databricks/sdk/core/error/ErrorDetail.java | 2 +- .../core/error/ApiErrorBodyDeserializationSuite.java | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/databricks-sdk-java/src/main/java/com/databricks/sdk/core/error/ErrorDetail.java b/databricks-sdk-java/src/main/java/com/databricks/sdk/core/error/ErrorDetail.java index 6b71ccc28..ae6ffb1ec 100644 --- a/databricks-sdk-java/src/main/java/com/databricks/sdk/core/error/ErrorDetail.java +++ b/databricks-sdk-java/src/main/java/com/databricks/sdk/core/error/ErrorDetail.java @@ -26,7 +26,7 @@ public ErrorDetail( this.type = type; this.reason = reason; this.domain = domain; - this.metadata = Collections.unmodifiableMap(metadata); + this.metadata = metadata != null ? Collections.unmodifiableMap(metadata) : null; } public String getType() { diff --git a/databricks-sdk-java/src/test/java/com/databricks/sdk/core/error/ApiErrorBodyDeserializationSuite.java b/databricks-sdk-java/src/test/java/com/databricks/sdk/core/error/ApiErrorBodyDeserializationSuite.java index f7b53b2ec..d87229870 100644 --- a/databricks-sdk-java/src/test/java/com/databricks/sdk/core/error/ApiErrorBodyDeserializationSuite.java +++ b/databricks-sdk-java/src/test/java/com/databricks/sdk/core/error/ApiErrorBodyDeserializationSuite.java @@ -64,4 +64,16 @@ void handleUnexpectedFieldsInErrorResponse() throws JsonProcessingException { assertEquals(error.getErrorCode(), "theerrorcode"); assertEquals(error.getMessage(), "themessage"); } + + @Test + void handleNullMetadataFieldInErrorResponse() throws JsonProcessingException { + ObjectMapper mapper = new ObjectMapper(); + String rawResponse = + "{\"error_code\":\"METASTORE_DOES_NOT_EXIST\",\"message\":\"No metastore assigned for the current workspace.\",\"details\":[{\"@type\":\"type.googleapis.com/google.rpc.RequestInfo\",\"request_id\":\"1888e822-f1b5-4996-85eb-0d2b5cc402e6\",\"serving_data\":\"\"}]}"; + ApiErrorBody error = mapper.readValue(rawResponse, ApiErrorBody.class); + + assertEquals(error.getErrorCode(), "METASTORE_DOES_NOT_EXIST"); + assertEquals(error.getMessage(), "No metastore assigned for the current workspace."); + } + }