Skip to content

Commit 368a02f

Browse files
committed
meh
1 parent 6c887ac commit 368a02f

File tree

3 files changed

+116
-1
lines changed

3 files changed

+116
-1
lines changed

test/api/test_api.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,3 +470,67 @@ def test_streaming_unstructured_ingest_error_with_none_status_code():
470470
"Async gen test UnstructuredIngestError with None status_code"
471471
in invoke_response.status_code_text
472472
)
473+
474+
475+
# Tests for UnstructuredIngestErrorV2
476+
@pytest.mark.parametrize(
477+
"file_data", mock_file_data, ids=[type(fd).__name__ for fd in mock_file_data]
478+
)
479+
def test_unstructured_ingest_error_v2_with_status_code(file_data):
480+
"""Test that UnstructuredIngestErrorV2 with status_code is handled correctly."""
481+
from test.assets.exception_status_code import (
482+
function_raises_unstructured_ingest_error_v2_with_status_code as test_fn,
483+
)
484+
485+
client = TestClient(wrap_in_fastapi(func=test_fn, plugin_id="mock_plugin"))
486+
487+
post_body = {"file_data": file_data.model_dump()}
488+
resp = client.post("/invoke", json=post_body)
489+
resp_content = resp.json()
490+
invoke_response = InvokeResponse.model_validate(resp_content)
491+
492+
# Should use the UnstructuredIngestErrorV2's status_code
493+
assert invoke_response.status_code == 400
494+
assert "Test UnstructuredIngestErrorV2 with status_code" in invoke_response.status_code_text
495+
496+
497+
@pytest.mark.parametrize(
498+
"file_data", mock_file_data, ids=[type(fd).__name__ for fd in mock_file_data]
499+
)
500+
def test_unstructured_ingest_error_v2_without_status_code(file_data):
501+
"""Test that UnstructuredIngestErrorV2 without status_code defaults to 500."""
502+
from test.assets.exception_status_code import (
503+
function_raises_unstructured_ingest_error_v2_without_status_code as test_fn,
504+
)
505+
506+
client = TestClient(wrap_in_fastapi(func=test_fn, plugin_id="mock_plugin"))
507+
508+
post_body = {"file_data": file_data.model_dump()}
509+
resp = client.post("/invoke", json=post_body)
510+
resp_content = resp.json()
511+
invoke_response = InvokeResponse.model_validate(resp_content)
512+
513+
# Should default to 500 when UnstructuredIngestErrorV2 has no status_code
514+
assert invoke_response.status_code == 500
515+
assert "Test UnstructuredIngestErrorV2 without status_code" in invoke_response.status_code_text
516+
517+
518+
@pytest.mark.parametrize(
519+
"file_data", mock_file_data, ids=[type(fd).__name__ for fd in mock_file_data]
520+
)
521+
def test_async_unstructured_ingest_error_v2(file_data):
522+
"""Test that async functions with UnstructuredIngestErrorV2 are handled correctly."""
523+
from test.assets.exception_status_code import (
524+
async_function_raises_unstructured_ingest_error_v2 as test_fn,
525+
)
526+
527+
client = TestClient(wrap_in_fastapi(func=test_fn, plugin_id="mock_plugin"))
528+
529+
post_body = {"file_data": file_data.model_dump()}
530+
resp = client.post("/invoke", json=post_body)
531+
resp_content = resp.json()
532+
invoke_response = InvokeResponse.model_validate(resp_content)
533+
534+
# Should use the UnstructuredIngestErrorV2's status_code
535+
assert invoke_response.status_code == 503
536+
assert "Async test UnstructuredIngestErrorV2" in invoke_response.status_code_text

test/assets/exception_status_code.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from fastapi import HTTPException
44
from unstructured_ingest.error import UnstructuredIngestError
5+
from unstructured_ingest.errors_v2 import UnstructuredIngestError as UnstructuredIngestErrorV2
56

67

78
class ExceptionWithNoneStatusCode(Exception):
@@ -137,3 +138,52 @@ async def async_gen_function_raises_unstructured_ingest_error_with_none_status_c
137138
error = UnstructuredIngestError("Async gen test UnstructuredIngestError with None status_code")
138139
error.status_code = None
139140
raise error
141+
142+
143+
# V2 Error Functions - using UnstructuredIngestErrorV2
144+
def function_raises_unstructured_ingest_error_v2_with_status_code():
145+
"""Function that raises UnstructuredIngestErrorV2 with status_code."""
146+
error = UnstructuredIngestErrorV2("Test UnstructuredIngestErrorV2 with status_code")
147+
error.status_code = 400
148+
raise error
149+
150+
151+
def function_raises_unstructured_ingest_error_v2_without_status_code():
152+
"""Function that raises UnstructuredIngestErrorV2 without status_code."""
153+
raise UnstructuredIngestErrorV2("Test UnstructuredIngestErrorV2 without status_code")
154+
155+
156+
def function_raises_unstructured_ingest_error_v2_with_none_status_code():
157+
"""Function that raises UnstructuredIngestErrorV2 with None status_code."""
158+
error = UnstructuredIngestErrorV2("Test UnstructuredIngestErrorV2 with None status_code")
159+
error.status_code = None
160+
raise error
161+
162+
163+
async def async_function_raises_unstructured_ingest_error_v2():
164+
"""Async function that raises UnstructuredIngestErrorV2."""
165+
error = UnstructuredIngestErrorV2("Async test UnstructuredIngestErrorV2")
166+
error.status_code = 503
167+
raise error
168+
169+
170+
async def async_gen_function_raises_unstructured_ingest_error_v2():
171+
"""Async generator that raises UnstructuredIngestErrorV2."""
172+
# Don't yield anything, just raise the exception
173+
if False: # This ensures the function is detected as a generator but never yields
174+
yield None
175+
error = UnstructuredIngestErrorV2("Async gen test UnstructuredIngestErrorV2")
176+
error.status_code = 502
177+
raise error
178+
179+
180+
async def async_gen_function_raises_unstructured_ingest_error_v2_with_none_status_code():
181+
"""Async generator that raises UnstructuredIngestErrorV2 with None status_code."""
182+
# Don't yield anything, just raise the exception
183+
if False: # This ensures the function is detected as a generator but never yields
184+
yield None
185+
error = UnstructuredIngestErrorV2(
186+
"Async gen test UnstructuredIngestErrorV2 with None status_code"
187+
)
188+
error.status_code = None
189+
raise error

unstructured_platform_plugins/etl_uvicorn/api_generator.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from starlette.responses import RedirectResponse
1414
from unstructured_ingest.data_types.file_data import BatchFileData, FileData, file_data_from_dict
1515
from unstructured_ingest.error import UnstructuredIngestError
16+
from unstructured_ingest.errors_v2 import UnstructuredIngestError as UnstructuredIngestErrorV2
1617
from uvicorn.config import LOG_LEVELS
1718
from uvicorn.importer import import_from_string
1819

@@ -224,7 +225,7 @@ async def _stream_response():
224225
else exc.detail,
225226
file_data=request_dict.get("file_data", None),
226227
)
227-
except UnstructuredIngestError as exc:
228+
except (UnstructuredIngestError, UnstructuredIngestErrorV2) as exc:
228229
logger.error(
229230
f"UnstructuredIngestError: {str(exc)} (status_code={exc.status_code})",
230231
exc_info=True,

0 commit comments

Comments
 (0)