23
23
get_schema_dict ,
24
24
map_inputs ,
25
25
)
26
+ from unstructured_platform_plugins .exceptions import UnrecoverableException
26
27
from unstructured_platform_plugins .schema .json_schema import (
27
28
schema_to_base_model ,
28
29
)
@@ -100,7 +101,7 @@ async def wrap_fn(func: Callable, kwargs: Optional[dict[str, Any]] = None) -> Re
100
101
if "usage" in inspect .signature (func ).parameters :
101
102
request_dict ["usage" ] = usage
102
103
else :
103
- logger .warning ("usage data not an expected parameter, omitting" )
104
+ logger .debug ("usage data not an expected parameter, omitting" )
104
105
try :
105
106
if inspect .isasyncgenfunction (func ):
106
107
# Stream response if function is an async generator
@@ -113,8 +114,15 @@ async def _stream_response():
113
114
114
115
return StreamingResponse (_stream_response (), media_type = "application/x-ndjson" )
115
116
else :
116
- output = await invoke_func (func = func , kwargs = request_dict )
117
- return InvokeResponse (usage = usage , status_code = status .HTTP_200_OK , output = output )
117
+ try :
118
+ output = await invoke_func (func = func , kwargs = request_dict )
119
+ return InvokeResponse (
120
+ usage = usage , status_code = status .HTTP_200_OK , output = output
121
+ )
122
+ except UnrecoverableException as ex :
123
+ # Thrower of this exception is responsible for logging necessary information
124
+ logger .info ("Unrecoverable error occurred during plugin invocation" )
125
+ return InvokeResponse (usage = usage , status_code = 512 , status_code_text = ex .message )
118
126
except Exception as invoke_error :
119
127
logger .error (f"failed to invoke plugin: { invoke_error } " , exc_info = True )
120
128
return InvokeResponse (
0 commit comments