|
4 | 4 | import os |
5 | 5 | import time |
6 | 6 | from typing import Any, Dict, List, Mapping, Optional |
7 | | - |
| 7 | +from contextlib import suppress |
8 | 8 | import httpx |
9 | 9 | import openai |
10 | 10 | from langchain_core.embeddings import Embeddings |
|
25 | 25 | get_uipath_token_header, |
26 | 26 | ) |
27 | 27 | from uipath_langchain._utils._sleep_policy import before_sleep_log |
28 | | - |
| 28 | +from uipath._cli._runtime._contracts import UiPathRuntimeError, UiPathErrorCategory |
29 | 29 |
|
30 | 30 | def get_from_uipath_url(): |
31 | 31 | url = os.getenv("UIPATH_URL") |
@@ -234,7 +234,7 @@ async def _arequest( |
234 | 234 | # Handle HTTP errors and map them to OpenAI exceptions |
235 | 235 | try: |
236 | 236 | response.raise_for_status() |
237 | | - except httpx.HTTPStatusError as err: |
| 237 | + except httpx.HTTPStatusError as err: |
238 | 238 | if self.logger: |
239 | 239 | self.logger.error( |
240 | 240 | "Error querying LLM: %s (%s)", |
@@ -348,6 +348,24 @@ def _make_status_error( |
348 | 348 | return openai.AuthenticationError(err_msg, response=response, body=data) |
349 | 349 |
|
350 | 350 | if response.status_code == 403: |
| 351 | + # Check if this is a license-specific error |
| 352 | + if isinstance(body, dict): |
| 353 | + title = body.get('title', '').lower() |
| 354 | + detail = body.get('detail', '').lower() |
| 355 | + |
| 356 | + # Smart detection of license errors |
| 357 | + if ('license' in title or 'license' in detail) and \ |
| 358 | + ('not available' in title or 'not available' in detail or |
| 359 | + 'unavailable' in title or 'unavailable' in detail): |
| 360 | + # Raise UiPathRuntimeError for license issues |
| 361 | + raise UiPathRuntimeError( |
| 362 | + code="LICENSE_NOT_AVAILABLE", |
| 363 | + title=body.get('title', 'License Not Available'), |
| 364 | + detail=body.get('detail', 'License not available for this service'), |
| 365 | + category=UiPathErrorCategory.DEPLOYMENT, |
| 366 | + prefix="UIPATH" |
| 367 | + ) |
| 368 | + |
351 | 369 | return openai.PermissionDeniedError(err_msg, response=response, body=data) |
352 | 370 |
|
353 | 371 | if response.status_code == 404: |
|
0 commit comments