-
Notifications
You must be signed in to change notification settings - Fork 5.2k
fix(exceptions): coerce APIStatusError.code to str to match Optional[str] annotation #3784
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import math | ||
| import time | ||
| import threading | ||
| from typing import Any, Generic, TypeVar, Callable, TypedDict, cast | ||
|
|
@@ -305,8 +306,10 @@ def _handle_token_response(self, response: httpx2.Response) -> dict[str, Any]: | |
| ) | ||
|
|
||
| def _validate_expires_in(self, expires_in: object) -> float: | ||
| if not isinstance(expires_in, (int, float)): | ||
| raise OpenAIError("Token exchange response did not include a valid expires_in") | ||
| if isinstance(expires_in, bool): | ||
| expires_in = int(expires_in) | ||
| if not isinstance(expires_in, (int, float)) or math.isnan(expires_in) or math.isinf(expires_in) or expires_in <= 0: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If a token response contains an oversized integer such as AGENTS.md reference: AGENTS.md:L41-L45 Useful? React with 👍 / 👎. |
||
| raise ValueError("Token exchange response did not include a valid expires_in") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When the token endpoint returns a newly rejected value such as AGENTS.md reference: AGENTS.md:L41-L45 Useful? React with 👍 / 👎. |
||
| return float(expires_in) | ||
|
|
||
| def _token_unusable(self) -> bool: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For a malformed JSON response containing
"expires_in": true, these lines turn the boolean into1.0, cache the token, and proceed with the API request even though booleans are not numeric expiration values; the X.509 validator explicitly rejects the same input. Return a validation error for both booleans and add focused sync/async coverage.AGENTS.md reference: AGENTS.md:L41-L45
Useful? React with 👍 / 👎.