Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.0.8

* **reduce usage data log level** We do not want to have so much verbosity for something that might happen a lot
* **Support unrecoverable errors** Throw a 512 error for an unrecoverable error

## 0.0.7

* **Improve code separation to help with unit tests**
Expand Down
2 changes: 1 addition & 1 deletion unstructured_platform_plugins/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.0.7" # pragma: no cover
__version__ = "0.0.8" # pragma: no cover
14 changes: 11 additions & 3 deletions unstructured_platform_plugins/etl_uvicorn/api_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
get_schema_dict,
map_inputs,
)
from unstructured_platform_plugins.exceptions import UnrecoverableException
from unstructured_platform_plugins.schema.json_schema import (
schema_to_base_model,
)
Expand Down Expand Up @@ -100,7 +101,7 @@ async def wrap_fn(func: Callable, kwargs: Optional[dict[str, Any]] = None) -> Re
if "usage" in inspect.signature(func).parameters:
request_dict["usage"] = usage
else:
logger.warning("usage data not an expected parameter, omitting")
logger.debug("usage data not an expected parameter, omitting")
try:
if inspect.isasyncgenfunction(func):
# Stream response if function is an async generator
Expand All @@ -113,8 +114,15 @@ async def _stream_response():

return StreamingResponse(_stream_response(), media_type="application/x-ndjson")
else:
output = await invoke_func(func=func, kwargs=request_dict)
return InvokeResponse(usage=usage, status_code=status.HTTP_200_OK, output=output)
try:
output = await invoke_func(func=func, kwargs=request_dict)
return InvokeResponse(
usage=usage, status_code=status.HTTP_200_OK, output=output
)
except UnrecoverableException as ex:
# Thrower of this exception is responsible for logging necessary information
logger.info("Unrecoverable error occurred during plugin invocation")
return InvokeResponse(usage=usage, status_code=512, status_code_text=ex.message)
except Exception as invoke_error:
logger.error(f"failed to invoke plugin: {invoke_error}", exc_info=True)
return InvokeResponse(
Expand Down
4 changes: 4 additions & 0 deletions unstructured_platform_plugins/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class UnrecoverableException(Exception):
def __init__(self, message: str):
super().__init__(message)
self.message = message
Loading