Skip to content

Commit 0bc2966

Browse files
committed
Expect only HTTPException from the plugins
1 parent 39c4536 commit 0bc2966

File tree

2 files changed

+7
-20
lines changed

2 files changed

+7
-20
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ dependencies = [
2525
"click",
2626
"unstructured-ingest",
2727
"unstructured-client",
28+
"platform-plugins",
2829
"opentelemetry-instrumentation-fastapi",
2930
"opentelemetry-exporter-otlp-proto-grpc",
3031
"dataclasses-json"

unstructured_platform_plugins/etl_uvicorn/api_generator.py

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,13 @@
44
import json
55
import logging
66
from functools import partial
7-
from shutil import ReadError
87
from typing import Any, Callable, Optional, Union
98

10-
from fastapi import FastAPI, status
11-
from fastapi.responses import JSONResponse, StreamingResponse
9+
from fastapi import FastAPI, HTTPException, status
10+
from fastapi.responses import StreamingResponse
1211
from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor
1312
from pydantic import BaseModel, Field, create_model
14-
from requests import ReadTimeout
1513
from starlette.responses import RedirectResponse
16-
from unstructured_client.models.errors import HTTPValidationError
1714
from unstructured_ingest.data_types.file_data import BatchFileData, FileData, file_data_from_dict
1815
from uvicorn.config import LOG_LEVELS
1916
from uvicorn.importer import import_from_string
@@ -211,22 +208,11 @@ async def _stream_response():
211208
output=output,
212209
file_data=request_dict.get("file_data", None),
213210
)
214-
except ReadError as exc:
215-
return JSONResponse(
216-
status_code=400,
217-
content={"detail": f"File read error: {str(exc)}"},
218-
)
219-
except ReadTimeout as exc:
220-
return JSONResponse(
221-
status_code=504,
222-
content={"detail": f"Partition service timeout: {str(exc)}"},
223-
)
224-
except HTTPValidationError as exc:
225-
logger.error(f"HTTP validation error: {exc}", exc_info=True)
226-
return JSONResponse(
227-
status_code=422,
228-
content={"detail": f"HTTP validation error: {str(exc)}"},
211+
except HTTPException as exc:
212+
logger.error(
213+
f"HTTPException: {exc.detail} (status_code={exc.status_code})", exc_info=True
229214
)
215+
raise
230216
except UnrecoverableException as ex:
231217
logger.info("Unrecoverable error occurred during plugin invocation")
232218
return InvokeResponse(

0 commit comments

Comments
 (0)