You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Correctly return TooManyRequests when receiving HTTP 429 errors. (#547)
## What changes are proposed in this pull request?
This PR fixes a bug where the Databricks Java SDK was returning a
generic `DatabricksError` instead of the specific `TooManyRequests`
exception for HTTP 429 (Too Many Requests) responses.
**Key Changes:**
**Removed hardcoded 429 handling** (`ApiErrors.java`):
- Previously, HTTP 429 responses were handled by a hardcoded check that
returned a generic `DatabricksError("TOO_MANY_REQUESTS", ...)`. This was
likely added as a quick fix in past but resulted in bypassing the
existing error mapping infrastructure that would have correctly returned
a `TooManyRequests` instance. Now, all HTTP errors (including 429) flow
through the `ErrorMapper`, which has the proper `statusCode(429,
TooManyRequests::new)` mapping.
**Refactored error parsing** (`ApiErrors.java`):
- `parseApiError()` now returns `Optional<ApiErrorBody>` to explicitly
handle cases where the response body is null or empty.
- When the response body is empty, `getDatabricksError()` passes an
empty `ApiErrorBody` to the `ErrorMapper`, which correctly infers the
error type based solely on the HTTP status code.
- Extracted `normalizeError()` method to centralize logic for handling
older API error formats (API v1.2 and SCIM errors).
**Simplified error flow** (`ApiClient.java`):
- Removed the dual error handling path that passed both `Response` and
`Exception` to `getDatabricksError()`.
- `IOException` during HTTP request execution is now immediately
converted to `DatabricksError("IO_ERROR", 523, exception)` without retry
logic.
- Signature simplified from `getDatabricksError(Response out, Exception
error)` to `getDatabricksError(Response response)`.
## How is this tested?
The change is covered by existing unit tests that have been adapted to
verify that 429 error are properly mapped to the right exception.
0 commit comments