Skip to content

Add optional strict HTTP mode #269

Description

@Mattsface

Add optional strict HTTP mode

Why

The package historically converts many 4xx responses into endpoint-level empty results.

This preserves compatibility but can hide authorization, malformed-request, rate-limit, and unsupported-operation failures.

Version 0.9.0 should let callers opt into stricter behavior without changing the default.

Parent release issue: #265

Proposed usage

import mlbstatsapi

mlb = mlbstatsapi.Mlb(
    strict_http=True,
)

Default behavior remains:

mlb = mlbstatsapi.Mlb(
    strict_http=False,
)

Strict-mode behavior

When strict_http=True:

  • Final non-404 4xx responses raise MlbHttpError
  • Final 5xx responses raise MlbHttpError
  • Final 429 responses raise after retries are exhausted
  • Transport and decoding exceptions retain their existing classes
  • Endpoint-specific 404 behavior remains unchanged

Compatibility-mode behavior

When strict_http=False:

  • Existing version 0.8.0 behavior remains the default
  • Existing endpoint return types remain unchanged
  • Existing endpoint-specific 404 behavior remains unchanged
  • Existing broad exception handling remains valid

Constructor compatibility

The new argument must be optional and must not break existing positional constructor usage.

Existing code must continue working:

mlb = mlbstatsapi.Mlb()

Testing requirements

Test both modes for:

400
401
403
404
405
422
429
500
502

Also test:

  • Default mode is compatibility mode
  • Strict mode is explicitly opt-in
  • Final non-404 4xx raises only in strict mode
  • 404 behavior remains unchanged in both modes
  • Final 5xx raises in both modes
  • Strict-mode exceptions contain the richer error context
  • Retry behavior occurs before the final strict-mode decision
  • Existing endpoint return tests continue passing in compatibility mode

Suggested branch

feat/strict-http-mode

The branch should start from and target:

release/0.9.0

Dependencies

Depends on:

Acceptance criteria

  • Strict mode is available through the public Mlb client
  • Compatibility mode remains the default
  • Non-404 4xx responses raise in strict mode
  • Existing 404 behavior remains unchanged
  • Existing constructor usage remains compatible
  • Existing endpoint behavior remains compatible by default
  • Offline tests pass
  • Relevant live tests pass

Not included

  • Strict mode as the default
  • Strict 404 exceptions
  • Endpoint return-type redesign
  • Removal of compatibility mode

Metadata

Metadata

Assignees

No one assigned

    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