Add richer context to MlbHttpError
Why
MlbHttpError currently exposes:
These fields identify the failure but may not provide enough information to understand an MLB API error response.
Version 0.9.0 should expose additional best-effort context without assuming the MLB API returns one consistent error schema.
Parent release issue: #265
Scope
Preserve the existing fields and add bounded response context.
Suggested attributes:
method
status_code
reason
url
response_data
body_excerpt
response_data
When an error response contains valid JSON, preserve the decoded dictionary or list when practical.
When the response is not valid JSON:
body_excerpt
Preserve a short, bounded excerpt of the response body.
The excerpt must:
- Have a fixed maximum length
- Never contain the complete contents of a large response
- Not cause a second exception during error handling
- Work for JSON, HTML, text, or empty responses
Compatibility requirements
Preserve:
exc.status_code
exc.reason
exc.url
Existing applications using those fields must continue working.
All HTTP exceptions must continue inheriting from:
Testing requirements
- Existing attributes remain unchanged
- JSON error responses populate
response_data
- Non-JSON responses set
response_data to None
- Empty responses are handled safely
- Large bodies are truncated
- The request method is preserved
- Exception string output remains concise
- Complete response bodies are not added to logs
- Error handling does not hide the original HTTP status
Suggested branch
The branch should start from and target:
Acceptance criteria
- Existing error attributes remain compatible
- Useful JSON error details are available when MLB provides them
- Non-JSON errors remain understandable
- Response excerpts are bounded
- No fixed MLB error-payload schema is assumed
- Offline tests pass
- Relevant live tests pass
Not included
- Strict mode
- Changing which status codes raise
- Retrying additional status codes
- Exposing complete response objects
- Logging complete response bodies
Add richer context to MlbHttpError
Why
MlbHttpErrorcurrently exposes:These fields identify the failure but may not provide enough information to understand an MLB API error response.
Version 0.9.0 should expose additional best-effort context without assuming the MLB API returns one consistent error schema.
Parent release issue: #265
Scope
Preserve the existing fields and add bounded response context.
Suggested attributes:
response_dataWhen an error response contains valid JSON, preserve the decoded dictionary or list when practical.
When the response is not valid JSON:
body_excerptPreserve a short, bounded excerpt of the response body.
The excerpt must:
Compatibility requirements
Preserve:
Existing applications using those fields must continue working.
All HTTP exceptions must continue inheriting from:
TheMlbStatsApiExceptionTesting requirements
response_dataresponse_datatoNoneSuggested branch
The branch should start from and target:
Acceptance criteria
Not included