|
4 | 4 | import json |
5 | 5 | import logging |
6 | 6 | from functools import partial |
7 | | -from shutil import ReadError |
8 | 7 | from typing import Any, Callable, Optional, Union |
9 | 8 |
|
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 |
12 | 11 | from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor |
13 | 12 | from pydantic import BaseModel, Field, create_model |
14 | | -from requests import ReadTimeout |
15 | 13 | from starlette.responses import RedirectResponse |
16 | | -from unstructured_client.models.errors import HTTPValidationError |
17 | 14 | from unstructured_ingest.data_types.file_data import BatchFileData, FileData, file_data_from_dict |
18 | 15 | from uvicorn.config import LOG_LEVELS |
19 | 16 | from uvicorn.importer import import_from_string |
@@ -211,22 +208,11 @@ async def _stream_response(): |
211 | 208 | output=output, |
212 | 209 | file_data=request_dict.get("file_data", None), |
213 | 210 | ) |
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 |
229 | 214 | ) |
| 215 | + raise |
230 | 216 | except UnrecoverableException as ex: |
231 | 217 | logger.info("Unrecoverable error occurred during plugin invocation") |
232 | 218 | return InvokeResponse( |
|
0 commit comments