openapi-python-generator
openapi-python-generator copied to clipboard
Design: Enhanced Error Handling for Generated Clients (#100)
Summary
This PR adds a comprehensive design document for Issue #100: Enhanced error handling for generated OpenAPI clients.
What's Included
The design document (DESIGN_ISSUE_100.md) specifies:
Core Features
-
Rich Exception Hierarchy:
APIError→ClientError/ServerErrorwith full HTTP context - Parsed Error Models: Automatic parsing of error responses from OpenAPI specs
- Dual API Pattern: Simple (direct models) + Detailed (response wrappers with metadata)
- Multiple Success Codes: Support all 2xx codes including wildcards (2XX, 4XX, 5XX)
- Type Safety: No Union[Success, Error] types - exceptions for errors, models for success
-
Backwards Compatible:
HTTPExceptionalias maintains existing code compatibility
Architecture
- Exception types with full context (status, method, URL, headers, request ID, body, parsed model)
-
DetailedResponse[T]wrapper with fluent API (on().otherwise().resolve()) - Helper utilities (
unwrap(),expect(),match(), type guards) - HTTP client agnostic (httpx, requests, aiohttp)
Implementation Plan
10-phase rollout covering:
- Core exceptions
- Response wrappers
- Utility functions
- Service generator updates
- Error creation functions
- Simple API generation
- Detailed API generation
- Type guards
- Integration testing
- Documentation
Next Steps
- Review & Approve Design: Community feedback on the proposed architecture
- Implementation Roadmap: Break down into separate issues/PRs (see issue for proposed roadmap)
- Phased Implementation: Tackle one phase at a time with focused PRs
Related
- Fixes #100
- Depends on static file infrastructure (#TBD - separate PR coming)
Request for Feedback
Please review:
- Overall architecture and design decisions
- API ergonomics (simple vs detailed patterns)
- Backwards compatibility approach
- Implementation phasing