|
1 | 1 | from collections.abc import Generator |
2 | 2 |
|
3 | | -from httpx import Auth, Client, HTTPStatusError, Request, Response |
| 3 | +from httpx import Auth, Client, Request, Response |
4 | 4 |
|
5 | 5 | from uipath_llm_client.settings.llmgateway.settings import LLMGatewayBaseSettings |
6 | 6 | from uipath_llm_client.settings.llmgateway.utils import LLMGatewayEndpoints |
7 | 7 | from uipath_llm_client.settings.utils import SingletonMeta |
8 | | -from uipath_llm_client.utils.exceptions import UiPathAPIError |
| 8 | +from uipath_llm_client.utils.exceptions import UiPathAPIError, UiPathAuthenticationError |
9 | 9 |
|
10 | 10 |
|
11 | 11 | class LLMGatewayS2SAuth(Auth, metaclass=SingletonMeta): |
@@ -39,10 +39,15 @@ def get_llmgw_token_header( |
39 | 39 | ) |
40 | 40 | with Client() as http_client: |
41 | 41 | response = http_client.post(url_get_token, data=token_credentials) |
42 | | - try: |
43 | | - response.raise_for_status() |
44 | | - except HTTPStatusError as e: |
45 | | - raise UiPathAPIError.from_response(e.response) |
| 42 | + if response.is_client_error: |
| 43 | + raise UiPathAuthenticationError( |
| 44 | + message="Failed to authenticate with LLM Gateway, invalid credentials", |
| 45 | + request=response.request, |
| 46 | + response=response, |
| 47 | + body=response.json(), |
| 48 | + ) |
| 49 | + elif response.is_error: |
| 50 | + raise UiPathAPIError.from_response(response) |
46 | 51 | llmgw_token_header = response.json().get("access_token") |
47 | 52 | return llmgw_token_header |
48 | 53 |
|
|
0 commit comments