Commit 2bd62c3
committed
refactor: improve error handling and streaming response management in Codex endpoints
Enhanced error handling for non-streaming Codex responses by properly
detecting and
returning error responses with correct HTTP status codes instead of
treating them as
streaming responses. Added comprehensive error response parsing to
handle various error
formats (detail, error, message fields) and improved streaming response
collection to
differentiate between actual streaming content and error responses.
Key improvements:
- Added error response detection in both streaming and non-streaming
paths
- Proper status code forwarding for error responses
- Enhanced JSON error parsing with fallback mechanisms
- Improved streaming response buffering and replay functionality
- Better content-type checking to distinguish between streaming and
error responses
- Added comprehensive error logging for debugging purposes
feat: improve Codex streaming response handling with proper header
management
- Capture and forward upstream response headers from Codex API
- Add comprehensive error handling for HTTP 4xx/5xx responses in
streaming mode
- Convert API errors to streaming-compatible JSON format with proper
error structure
- Filter out conflicting headers (content-length, content-encoding,
date) for streaming responses
- Implement header capture pattern in both codex.py and proxy_service.py
- Ensure streaming responses maintain proper SSE format even for error
conditions
- Add debug logging for response headers and error conditions
refactor: simplify Codex adapter imports and consolidate response
handling
- Removed unused CodexAdapter and CodexResponseChoice from
adapters/codex/__init__.py
- Consolidated Codex models to use centralized request/response models
from ccproxy.models
- Simplified response data extraction in response_adapter.py by removing
redundant type checks
- Enhanced codex chat completions route with improved error handling and
streaming logic
- Added proper type hints and error response handling for better
debugging
- Streamlined SSE event processing with clearer reasoning block
detection
- Fixed response format conversion to maintain consistency with OpenAI
Chat Completions API
The changes consolidate Codex-related code organization, improve error
handling robustness, and enhance the streaming response conversion
between Response API format and Chat Completions format. This reduces
code duplication and improves maintainability while ensuring proper
OpenAI API compatibility.1 parent c6fb72b commit 2bd62c3
File tree
4 files changed
+854
-537
lines changed- ccproxy
- adapters
- codex
- openai
- api/routes
- services
4 files changed
+854
-537
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
| 3 | + | |
| 4 | + | |
10 | 5 | | |
11 | 6 | | |
12 | 7 | | |
13 | | - | |
14 | 8 | | |
15 | 9 | | |
16 | 10 | | |
17 | | - | |
18 | 11 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
| 126 | + | |
| 127 | + | |
126 | 128 | | |
127 | | - | |
128 | | - | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
129 | 132 | | |
130 | | - | |
| 133 | + | |
131 | 134 | | |
132 | | - | |
133 | | - | |
134 | | - | |
| 135 | + | |
135 | 136 | | |
136 | 137 | | |
137 | 138 | | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
147 | 147 | | |
148 | 148 | | |
149 | | - | |
| 149 | + | |
150 | 150 | | |
151 | | - | |
| 151 | + | |
152 | 152 | | |
153 | | - | |
| 153 | + | |
154 | 154 | | |
155 | | - | |
156 | | - | |
| 155 | + | |
| 156 | + | |
157 | 157 | | |
158 | 158 | | |
159 | 159 | | |
| |||
164 | 164 | | |
165 | 165 | | |
166 | 166 | | |
167 | | - | |
| 167 | + | |
168 | 168 | | |
169 | 169 | | |
170 | 170 | | |
| |||
310 | 310 | | |
311 | 311 | | |
312 | 312 | | |
313 | | - | |
| 313 | + | |
314 | 314 | | |
315 | 315 | | |
316 | 316 | | |
317 | 317 | | |
318 | | - | |
| 318 | + | |
319 | 319 | | |
320 | 320 | | |
321 | 321 | | |
| |||
0 commit comments