Skip to content

Add richer context to MlbHttpError #268

Description

@Mattsface

Add richer context to MlbHttpError

Why

MlbHttpError currently exposes:

status_code
reason
url

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:

response_data = None

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:

TheMlbStatsApiException

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

feat/http-error-context

The branch should start from and target:

release/0.9.0

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions