feat(csharp/src/Drivers/Databricks): capture x-thriftserver-error-message header#3558
Conversation
…header Add ThriftErrorMessageHandler to capture and surface detailed error messages from the x-thriftserver-error-message HTTP response header when Thrift operations fail with HTTP error codes (401, 403, etc.). Previously, when authentication or authorization failed, users would only see generic HTTP status messages like 'Response status code does not indicate success: 401 (Unauthorized)', losing the specific error message from the Databricks Thrift server. Now, users see detailed error messages like: - 'Thrift server error: Invalid personal access token (HTTP 401 Unauthorized)' - 'Thrift server error: Token has expired (HTTP 401 Unauthorized)' - 'Thrift server error: User does not have permission to access catalog (HTTP 403 Forbidden)' Changes: - Add ThriftErrorMessageHandler as a DelegatingHandler - Integrate handler into DatabricksConnection HTTP handler chain - Add comprehensive unit tests (11 test cases, all passing) - Handler is compatible with .NET Framework 4.7.2, .NET Standard 2.0, and .NET 8.0 The handler is positioned as the innermost handler in the chain to capture response headers before other handlers or the Thrift transport can dispose of the response.
bcdf670 to
cc9f2c5
Compare
|
If the response has e.g. a 401 status with a |
Before the change: The exception flow is:
After the change (with ThriftErrorMessageHandler): The exception flow is:
It should still work for 401 mapping to Adbc authenticated exception since this block is checking on the error message. |
Rationale for this change
When the Databricks ADBC C# driver encounters HTTP errors during Thrift operations (e.g., 401 Unauthorized, 403 Forbidden), the specific error message from the Databricks server is lost. The server includes detailed error information in the
x-thriftserver-error-messageHTTP response header, but currently only generic HTTP status messages reach users.This makes debugging authentication and authorization issues difficult, as users cannot distinguish between different failure causes (expired token vs. invalid token vs. insufficient permissions).
What changes are included in this PR?
ThriftErrorMessageHandleras a newDelegatingHandlerthat intercepts HTTP error responsesx-thriftserver-error-messageheader and include it in exception messagesDatabricksConnectionHTTP handler chain as the innermost handlerAre these changes tested?
Yes. Added
ThriftErrorMessageHandlerTest.cswith 11 unit tests covering:All tests pass:
Build verification also passed for all target frameworks.
Are there any user-facing changes?
Yes - users will now see detailed error messages from Databricks instead of generic HTTP status codes:
Before:
After:
This is a backward-compatible enhancement - if the header is not present, behavior is unchanged.
Closes #3557