fix: preserve HTTPException status in proxy service error wrapping#768
fix: preserve HTTPException status in proxy service error wrapping#768jayesh-bansal wants to merge 1 commit into
Conversation
When provider resolution fails (e.g. a provider API key is missing),
api.dependencies._resolve_with_registry raises a curated HTTPException
503 whose detail is an actionable config hint ("NVIDIA_NIM_API_KEY is
not set. Add it to your .env file."). ClaudeProxyService.create_message
and count_tokens caught it in the generic `except Exception` handler and
re-wrapped it as HTTPException(500, "503: <detail>") - clients saw an
opaque 500 Internal Server Error with the real status embedded in the
message text (as reported in Alishahryar1#754).
Re-raise HTTPException before the generic handler so the curated status
and detail reach the client unchanged. Claude Code then receives a
proper 503 and can surface the configuration hint instead of failing
sub-agent runs with a generic 500.
- api/services.py: add `except HTTPException: raise` ahead of the
generic wrapper in create_message and count_tokens
- tests: 503 status and detail preserved end-to-end for both paths
Refs Alishahryar1#754
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR ensures curated HTTPExceptions raised by provider resolution/token counting propagate unchanged (status code + detail), instead of being re-wrapped into generic 500 responses.
Changes:
- Re-raise
HTTPExceptioninClaudeProxyService.create_messageandcount_tokensto preserve original status/detail. - Add regression tests asserting
HTTPExceptionstatus/detail are preserved. - Bump project version to
1.2.42.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tests/api/test_safe_logging.py | Adds tests verifying HTTPException is not re-wrapped as 500 in create_message/count_tokens. |
| api/services.py | Updates exception handling to re-raise HTTPException unchanged. |
| pyproject.toml | Increments project version for release. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| except ProviderError: | ||
| raise | ||
| except HTTPException: | ||
| # Provider resolution raises curated HTTPExceptions (e.g. 503 with a | ||
| # config hint when a provider key is missing); preserve their status | ||
| # instead of re-wrapping as a generic 500. | ||
| raise |
| """Curated HTTPExceptions (e.g. 503 missing-key hints) must not become 500s.""" | ||
| detail = "NVIDIA_NIM_API_KEY is not set. Add it to your .env file." |
Greptile SummaryThis PR fixes a bug where
Confidence Score: 5/5Safe to merge — the change is a two-line guard that lets already-curated HTTPExceptions pass through unmodified, with no impact on the existing ProviderError or generic Exception paths. The fix is minimal and surgical: inserting No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant Client
participant ClaudeProxyService
participant ProviderResolver
Client->>ClaudeProxyService: create_message / count_tokens
ClaudeProxyService->>ProviderResolver: resolve provider
ProviderResolver-->>ClaudeProxyService: raises HTTPException(503, "key missing hint")
note over ClaudeProxyService: Before fix: caught by except Exception<br/>→ re-wrapped as HTTPException(500, "503: ...")
note over ClaudeProxyService: After fix: caught by except HTTPException: raise<br/>→ original 503 + detail passed through
ClaudeProxyService-->>Client: HTTPException(503, "NVIDIA_NIM_API_KEY is not set...")
Reviews (1): Last reviewed commit: "fix: preserve HTTPException status in pr..." | Re-trigger Greptile |
When provider resolution fails (e.g. a provider API key is missing), api.dependencies._resolve_with_registry raises a curated HTTPException 503 whose detail is an actionable config hint ("NVIDIA_NIM_API_KEY is not set. Add it to your .env file."). ClaudeProxyService.create_message and count_tokens caught it in the generic
except Exceptionhandler and re-wrapped it as HTTPException(500, "503: ") - clients saw an opaque 500 Internal Server Error with the real status embedded in the message text (as reported in #754).Re-raise HTTPException before the generic handler so the curated status and detail reach the client unchanged. Claude Code then receives a proper 503 and can surface the configuration hint instead of failing sub-agent runs with a generic 500.
except HTTPException: raiseahead of the generic wrapper in create_message and count_tokensRefs #754