Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions unstructured_platform_plugins/etl_uvicorn/api_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from uvicorn.config import LOG_LEVELS
from uvicorn.importer import import_from_string

from unstructured_platform_plugins.etl_uvicorn.errors import wrap_error
from unstructured_platform_plugins.etl_uvicorn.otel import get_metric_provider, get_trace_provider
from unstructured_platform_plugins.etl_uvicorn.utils import (
get_func,
Expand Down Expand Up @@ -185,15 +184,16 @@ async def _stream_response():
)
except Exception as e:
logger.error(f"Failure streaming response: {e}", exc_info=True)
http_error = wrap_error(e)
yield (
InvokeResponse(
usage=usage,
message_channels=message_channels,
filedata_meta=filedata_meta_model.model_validate(
filedata_meta.model_dump()
),
status_code=http_error.status_code,
status_code=e.status_code
if hasattr(e, "status_code")
else status.HTTP_500_INTERNAL_SERVER_ERROR,
Copy link

Copilot AI Aug 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The inline conditional logic for status_code extraction is duplicated in two places (lines 194-196 and 233-235). Consider extracting this logic into a helper function to reduce code duplication and improve maintainability.

Suggested change
else status.HTTP_500_INTERNAL_SERVER_ERROR,
status_code=get_status_code_from_exception(e),

Copilot uses AI. Check for mistakes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code duplication is minimum here

status_code_text=f"[{e.__class__.__name__}] {e}",
).model_dump_json()
+ "\n"
Expand Down Expand Up @@ -226,12 +226,13 @@ async def _stream_response():
)
except Exception as invoke_error:
logger.error(f"failed to invoke plugin: {invoke_error}", exc_info=True)
http_error = wrap_error(invoke_error)
return InvokeResponse(
usage=usage,
message_channels=message_channels,
filedata_meta=filedata_meta_model.model_validate(filedata_meta.model_dump()),
status_code=http_error.status_code,
status_code=invoke_error.status_code
if hasattr(invoke_error, "status_code")
else status.HTTP_500_INTERNAL_SERVER_ERROR,
status_code_text=f"[{invoke_error.__class__.__name__}] {invoke_error}",
file_data=request_dict.get("file_data", None),
)
Expand Down