PR2: Map Server & HTTP Errors to Typed Exceptions + Fix URL-Length Validation #1493
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Metadata
Reference Issue: Fixes #1491
New Tests Added: No (tests covered in PR3 per roadmap)
Documentation Updated: No
Details
What This PR Implements
This PR introduces structured error mapping in _api_calls.py, enabling the OpenML Python client to raise typed, semantically meaningful exceptions in response to:
1. HTTP Status Codes → Typed Exceptions
2. OpenML XML Error Codes → Typed Exceptions
Includes mappings for:
3. Message-Based Fallback Classification
When server responses return:
…the client now makes reasonable inferences for:
authentication failures, rate limits, validation errors, missing resources, timeouts, and server outages.
4. Pre-check for Overly Long URLs (Fix for test_too_long_uri)
Before sending a request:
This resolves:
Why This Change Is Necessary
The prior system funneled most server errors into OpenMLServerError or OpenMLServerException, providing limited diagnostic value.
Typed exceptions allow:
This PR also fixes a longstanding edge case where very long URLs caused inconsistent failures.
How to Reproduce the Issue
Previously:
After this PR:
Additional Notes / Pre-commit Status
Some Ruff warnings remain for maintainers to decide:
These were intentionally not addressed in this PR to avoid breaking changes or large refactors.