2323 get_schema_dict ,
2424 map_inputs ,
2525)
26+ from unstructured_platform_plugins .exceptions import UnrecoverableException
2627from unstructured_platform_plugins .schema .json_schema import (
2728 schema_to_base_model ,
2829)
@@ -100,7 +101,7 @@ async def wrap_fn(func: Callable, kwargs: Optional[dict[str, Any]] = None) -> Re
100101 if "usage" in inspect .signature (func ).parameters :
101102 request_dict ["usage" ] = usage
102103 else :
103- logger .warning ("usage data not an expected parameter, omitting" )
104+ logger .debug ("usage data not an expected parameter, omitting" )
104105 try :
105106 if inspect .isasyncgenfunction (func ):
106107 # Stream response if function is an async generator
@@ -113,8 +114,15 @@ async def _stream_response():
113114
114115 return StreamingResponse (_stream_response (), media_type = "application/x-ndjson" )
115116 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 )
118126 except Exception as invoke_error :
119127 logger .error (f"failed to invoke plugin: { invoke_error } " , exc_info = True )
120128 return InvokeResponse (
0 commit comments