mirror of
https://github.com/run-llama/llama_cloud_services.git
synced 2026-07-25 08:05:26 -04:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| defb9e3ecb |
@@ -1015,11 +1015,20 @@ class LlamaParse(BasePydanticReader):
|
|||||||
try:
|
try:
|
||||||
url = build_url(JOB_UPLOAD_ROUTE, self.organization_id, self.project_id)
|
url = build_url(JOB_UPLOAD_ROUTE, self.organization_id, self.project_id)
|
||||||
resp = await make_api_request(self.aclient, "POST", url, timeout=self.max_timeout, files=files, data=data) # type: ignore
|
resp = await make_api_request(self.aclient, "POST", url, timeout=self.max_timeout, files=files, data=data) # type: ignore
|
||||||
resp.raise_for_status() # this raises if status is not 2xx
|
# Note: make_api_request already calls raise_for_status(), so no need to call it again
|
||||||
return resp.json()["id"]
|
return resp.json()["id"]
|
||||||
except httpx.HTTPStatusError as err: # this catches it
|
except httpx.HTTPStatusError as err: # this catches HTTP status errors
|
||||||
msg = f"Failed to parse the file: {err.response.text}"
|
msg = f"Failed to parse the file: {err.response.text}"
|
||||||
raise Exception(msg) from err # this preserves the exception context
|
raise Exception(msg) from err # this preserves the exception context
|
||||||
|
except Exception as err: # this catches other exceptions like RetryError, ValueError, etc.
|
||||||
|
# Try to extract meaningful error message from the exception chain
|
||||||
|
if hasattr(err, '__cause__') and isinstance(err.__cause__, httpx.HTTPStatusError):
|
||||||
|
# If the exception was caused by an HTTPStatusError, extract the response text
|
||||||
|
msg = f"Failed to parse the file: {err.__cause__.response.text}"
|
||||||
|
else:
|
||||||
|
# For other exceptions, use the string representation
|
||||||
|
msg = f"Failed to parse the file: {str(err)}"
|
||||||
|
raise Exception(msg) from err
|
||||||
finally:
|
finally:
|
||||||
if file_handle is not None:
|
if file_handle is not None:
|
||||||
file_handle.close()
|
file_handle.close()
|
||||||
@@ -1578,7 +1587,7 @@ class LlamaParse(BasePydanticReader):
|
|||||||
resp = await make_api_request(
|
resp = await make_api_request(
|
||||||
client, "GET", asset_url, timeout=self.max_timeout
|
client, "GET", asset_url, timeout=self.max_timeout
|
||||||
)
|
)
|
||||||
resp.raise_for_status()
|
# Note: make_api_request already calls raise_for_status()
|
||||||
f.write(resp.content)
|
f.write(resp.content)
|
||||||
assets.append(asset)
|
assets.append(asset)
|
||||||
return assets
|
return assets
|
||||||
@@ -1676,7 +1685,7 @@ class LlamaParse(BasePydanticReader):
|
|||||||
res = await make_api_request(
|
res = await make_api_request(
|
||||||
client, "GET", xlsx_url, timeout=self.max_timeout
|
client, "GET", xlsx_url, timeout=self.max_timeout
|
||||||
)
|
)
|
||||||
res.raise_for_status()
|
# Note: make_api_request already calls raise_for_status()
|
||||||
f.write(res.content)
|
f.write(res.content)
|
||||||
xlsx_list.append(xlsx)
|
xlsx_list.append(xlsx)
|
||||||
return xlsx_list
|
return xlsx_list
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ from tenacity import (
|
|||||||
wait_exponential,
|
wait_exponential,
|
||||||
retry_if_exception,
|
retry_if_exception,
|
||||||
before_sleep_log,
|
before_sleep_log,
|
||||||
|
RetryError,
|
||||||
)
|
)
|
||||||
from typing import Any, Iterable, Iterator, Optional, List, cast
|
from typing import Any, Iterable, Iterator, Optional, List, cast
|
||||||
|
|
||||||
@@ -300,7 +301,17 @@ async def make_api_request(
|
|||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
return response
|
return response
|
||||||
|
|
||||||
return await _make_request(url, **httpx_kwargs)
|
try:
|
||||||
|
return await _make_request(url, **httpx_kwargs)
|
||||||
|
except RetryError as retry_err:
|
||||||
|
# Extract the last exception from the retry error to preserve the original error details
|
||||||
|
if retry_err.last_attempt and retry_err.last_attempt.exception():
|
||||||
|
last_exception = retry_err.last_attempt.exception()
|
||||||
|
# Re-raise the original exception to preserve error details like response.text
|
||||||
|
raise last_exception from retry_err
|
||||||
|
else:
|
||||||
|
# Fallback if we can't extract the original exception
|
||||||
|
raise retry_err
|
||||||
|
|
||||||
|
|
||||||
def expand_target_pages(target_pages: str) -> Iterator[int]:
|
def expand_target_pages(target_pages: str) -> Iterator[int]:
|
||||||
|
|||||||
Reference in New Issue
Block a user