Skip to content

Commit a8e339e

Browse files
authored
Add more error logs in http response validation (databricks#1197)
## Description - The request ID is typically in the response header; this PR adds it to the error message for easier debugging. ## Testing - Manually testing BYOT flow error scenario ## Additional Notes to the Reviewer <!-- Share any additional context or insights that may help the reviewer understand the changes better. This could include challenges faced, limitations, or compromises made during the development process. Also, mention any areas of the code that you would like the reviewer to focus on specifically. -->
1 parent f6691ce commit a8e339e

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/main/java/com/databricks/jdbc/common/DatabricksJdbcConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public final class DatabricksJdbcConstants {
6262
public static final String USER_HOME_PROPERTY = "user.home";
6363
public static final String PORT = "port";
6464
public static final int DEFAULT_PORT = 443;
65+
public static final String REQUEST_ID_HEADER = "x-request-id";
6566
public static final String THRIFT_ERROR_MESSAGE_HEADER = "X-Thriftserver-Error-Message";
6667
public static final String ALLOWED_VOLUME_INGESTION_PATHS = "VolumeOperationAllowedLocalPaths";
6768
public static final String ENABLE_VOLUME_OPERATIONS = "enableVolumeOperations";

src/main/java/com/databricks/jdbc/common/util/ValidationUtil.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,27 +102,32 @@ public static String checkHTTPErrorWithoutThrowingError(HttpResponse response) {
102102
return EMPTY_STRING;
103103
}
104104
String statusLine = response.getStatusLine().toString();
105-
String errorReason =
106-
String.format("HTTP request failed by code: %d, status line: %s.", statusCode, statusLine);
105+
StringBuilder errorBuilder = new StringBuilder();
106+
errorBuilder.append(
107+
String.format("HTTP request failed by code: %d, status line: %s.", statusCode, statusLine));
107108
if (response.containsHeader(THRIFT_ERROR_MESSAGE_HEADER)) {
108-
errorReason +=
109+
errorBuilder.append(
109110
String.format(
110111
" Thrift Header : %s",
111-
response.getFirstHeader(THRIFT_ERROR_MESSAGE_HEADER).getValue());
112+
response.getFirstHeader(THRIFT_ERROR_MESSAGE_HEADER).getValue()));
113+
}
114+
if (response.containsHeader(REQUEST_ID_HEADER)) {
115+
String requestId = response.getFirstHeader(REQUEST_ID_HEADER).getValue();
116+
errorBuilder.append(String.format(" Request ID: %s.", requestId));
112117
}
113118
if (response.getEntity() != null) {
114119
try {
115120
JsonNode jsonNode =
116121
JsonUtil.getMapper().readTree(EntityUtils.toString(response.getEntity()));
117122
JsonNode errorNode = jsonNode.path("message");
118123
if (errorNode.isTextual()) {
119-
errorReason += String.format(" Error message: %s", errorNode.textValue());
124+
errorBuilder.append(String.format(" Error message: %s", errorNode.textValue()));
120125
}
121126
} catch (Exception e) {
122127
LOGGER.warn("Unable to parse JSON from response entity", e);
123128
}
124129
}
125-
return errorReason;
130+
return errorBuilder.toString();
126131
}
127132

128133
public static void checkHTTPError(HttpResponse response)

0 commit comments

Comments
 (0)