|
6 | 6 | from functools import partial |
7 | 7 | from typing import Any, Callable, Optional, Union |
8 | 8 |
|
9 | | -from fastapi import FastAPI, status |
| 9 | +from fastapi import FastAPI, HTTPException, status |
10 | 10 | from fastapi.responses import StreamingResponse |
11 | 11 | from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor |
12 | 12 | from pydantic import BaseModel, Field, create_model |
@@ -208,6 +208,18 @@ async def _stream_response(): |
208 | 208 | output=output, |
209 | 209 | file_data=request_dict.get("file_data", None), |
210 | 210 | ) |
| 211 | + except HTTPException as exc: |
| 212 | + logger.error( |
| 213 | + f"HTTPException: {exc.detail} (status_code={exc.status_code})", exc_info=True |
| 214 | + ) |
| 215 | + return InvokeResponse( |
| 216 | + usage=usage, |
| 217 | + message_channels=message_channels, |
| 218 | + filedata_meta=filedata_meta_model.model_validate(filedata_meta.model_dump()), |
| 219 | + status_code=wrap_error(exc).status_code, |
| 220 | + status_code_text=f"[{exc.__class__.__name__}] {exc}", |
| 221 | + file_data=request_dict.get("file_data", None), |
| 222 | + ) |
211 | 223 | except UnrecoverableException as ex: |
212 | 224 | logger.info("Unrecoverable error occurred during plugin invocation") |
213 | 225 | return InvokeResponse( |
|
0 commit comments