Skip to content

Commit 2963a78

Browse files
DGideaslramos15
andauthored
Improve error handling in handleError function to provide detailed reason for 404 responses (#1073)
Co-authored-by: Logan Ramos <[email protected]>
1 parent f1f2a07 commit 2963a78

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/platform/openai/node/fetch.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,11 +333,20 @@ async function handleError(
333333
}
334334

335335
if (response.status === 404) {
336+
let errorReason: string;
337+
338+
// Check if response body is valid JSON
339+
if (!jsonData) {
340+
errorReason = text;
341+
} else {
342+
errorReason = JSON.stringify(jsonData);
343+
}
344+
336345
return {
337346
type: FetchResponseKind.Failed,
338347
modelRequestId: modelRequestIdObj,
339348
failKind: ChatFailKind.NotFound,
340-
reason: 'Resource not found'
349+
reason: errorReason
341350
};
342351
}
343352

0 commit comments

Comments
 (0)