-
Notifications
You must be signed in to change notification settings - Fork 33
fix: check can consume licensing error [JAR-9330] #725
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| """Convert LLM provider HTTP errors into structured AgentRuntimeErrors. | ||
|
|
||
| Each LLM provider wraps HTTP errors in a different exception type: | ||
| - OpenAI: openai.PermissionDeniedError → e.status_code | ||
| - Vertex: google.genai.errors.ClientError → e.code | ||
| - Bedrock: botocore.exceptions.ClientError → e.response dict | ||
|
|
||
| This module extracts the HTTP status code from any of these and re-raises | ||
| as an AgentRuntimeError so that upstream error handling (exception mapper, | ||
| CAS bridge) can categorise by status code without provider-specific logic. | ||
| """ | ||
|
|
||
| from uipath.runtime.errors import UiPathErrorCategory | ||
|
|
||
| from uipath_langchain.agent.exceptions.exceptions import ( | ||
| AgentRuntimeError, | ||
| AgentRuntimeErrorCode, | ||
| ) | ||
|
|
||
|
|
||
| def _extract_status_code(e: BaseException) -> int | None: | ||
| """Extract HTTP status code from any provider-specific exception. | ||
|
|
||
| Supports OpenAI (status_code), Vertex/google.genai (code), and | ||
| Bedrock/botocore (response dict). Walks __cause__ chain to handle | ||
| LangChain wrapper exceptions (e.g. ChatGoogleGenerativeAIError). | ||
| """ | ||
| # OpenAI: e.status_code | ||
| sc = getattr(e, "status_code", None) | ||
| if isinstance(sc, int): | ||
| return sc | ||
|
|
||
| # Vertex (google.genai.errors.APIError): e.code | ||
| sc = getattr(e, "code", None) | ||
| if isinstance(sc, int): | ||
| return sc | ||
|
|
||
| # Bedrock (botocore.exceptions.ClientError): e.response dict | ||
| resp = getattr(e, "response", None) | ||
| if isinstance(resp, dict): | ||
| sc = resp.get("ResponseMetadata", {}).get("HTTPStatusCode") | ||
| if isinstance(sc, int): | ||
| return sc | ||
|
|
||
| # Walk __cause__ chain | ||
| cause = getattr(e, "__cause__", None) | ||
| if cause is not None and cause is not e: | ||
| return _extract_status_code(cause) | ||
|
|
||
| return None | ||
|
|
||
|
|
||
| # Maps known LLM Gateway status codes to specific error codes. | ||
| # Unknown status codes fall back to HTTP_ERROR. | ||
| _LLM_STATUS_CODE_MAP: dict[int, AgentRuntimeErrorCode] = { | ||
| 403: AgentRuntimeErrorCode.LICENSE_NOT_AVAILABLE, | ||
| } | ||
|
|
||
|
|
||
| def raise_for_provider_http_error(e: BaseException) -> None: | ||
| """Re-raise provider-specific HTTP errors as a structured AgentRuntimeError. | ||
|
|
||
| Extracts the HTTP status code from any LLM provider exception and | ||
| converts it to an AgentRuntimeError with the status code preserved. | ||
| Known status codes (e.g. 403) get a specific error code so upstream | ||
| handlers can match on the suffix. Does nothing if no HTTP status code | ||
| can be extracted. | ||
| """ | ||
| sc = _extract_status_code(e) | ||
| if sc is None: | ||
| return | ||
|
|
||
| code = _LLM_STATUS_CODE_MAP.get(sc, AgentRuntimeErrorCode.HTTP_ERROR) | ||
|
|
||
| if sc == 403: | ||
| category = UiPathErrorCategory.DEPLOYMENT | ||
| else: | ||
| category = UiPathErrorCategory.UNKNOWN | ||
|
|
||
| raise AgentRuntimeError( | ||
| code=code, | ||
| title=f"LLM provider returned HTTP {sc}", | ||
| detail=str(e), | ||
| category=category, | ||
| status=sc, | ||
| ) from e | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
nit: since we have specific error codes we could set meaningful title and details as well. The logic for the
exception_mapperis to not touchAgentRuntimeErrorsand assume that they are already correct with meaningful messages.Fine to leave this as a further improvement