@@ -82,11 +82,13 @@ async def invoke_app(
82
82
url = f"{ uri } /generate"
83
83
payload = await make_payload (datapoint , parameters , openapi_parameters )
84
84
async with aiohttp .ClientSession () as client :
85
+ app_response = {}
86
+
85
87
try :
86
88
logger .debug (f"Invoking app { uri } with payload { payload } " )
87
89
response = await client .post (url , json = payload , timeout = 900 )
88
- response .raise_for_status ()
89
90
app_response = await response .json ()
91
+ response .raise_for_status ()
90
92
return InvokationResult (
91
93
result = Result (
92
94
type = "text" ,
@@ -98,8 +100,12 @@ async def invoke_app(
98
100
)
99
101
100
102
except aiohttp .ClientResponseError as e :
101
- error_message = f"HTTP error { e .status } : { e .message } "
102
- stacktrace = "" .join (traceback .format_exception_only (type (e ), e ))
103
+ error_message = app_response .get ("detail" , {}).get (
104
+ "error" , f"HTTP error { e .status } : { e .message } "
105
+ )
106
+ stacktrace = app_response .get ("detail" , {}).get (
107
+ "traceback" , "" .join (traceback .format_exception_only (type (e ), e ))
108
+ )
103
109
logger .error (f"HTTP error occurred during request: { error_message } " )
104
110
common .capture_exception_in_sentry (e )
105
111
except aiohttp .ServerTimeoutError as e :
@@ -184,6 +190,7 @@ async def run_with_retry(
184
190
if retries == max_retry_count
185
191
else f"Error processing { input_data } datapoint"
186
192
)
193
+
187
194
return InvokationResult (
188
195
result = Result (
189
196
type = "error" ,
@@ -245,6 +252,7 @@ async def run_batch(start_idx: int):
245
252
246
253
# Gather results of all tasks
247
254
results = await asyncio .gather (* tasks )
255
+
248
256
for result in results :
249
257
list_of_app_outputs .append (result )
250
258
print (f"Adding outputs to batch { start_idx } " )
@@ -257,6 +265,7 @@ async def run_batch(start_idx: int):
257
265
258
266
# Start the first batch
259
267
await run_batch (0 )
268
+
260
269
return list_of_app_outputs
261
270
262
271
0 commit comments