Merge pull request #49 from ainoya/improve-error-response

fix: improve error handling for AI service responses
This commit is contained in:
Sean Goedecke
2025-07-16 12:42:38 +10:00
committed by GitHub
3 changed files with 36 additions and 11 deletions
Generated Vendored
+15 -5
View File
@@ -34406,13 +34406,23 @@ async function run() {
}
});
if (isUnexpected(response)) {
if (response.body.error) {
// Extract x-ms-error-code from headers if available
const errorCode = response.headers['x-ms-error-code'];
const errorCodeMsg = errorCode ? ` (error code: ${errorCode})` : '';
// Check if response body exists and contains error details
if (response.body && response.body.error) {
throw response.body.error;
}
throw new Error('An error occurred while fetching the response (' +
response.status +
'): ' +
response.body);
// Handle case where response body is missing
if (!response.body) {
throw new Error(`Failed to get response from AI service (status: ${response.status})${errorCodeMsg}. ` +
'Please check network connection and endpoint configuration.');
}
// Handle other error cases
throw new Error(`AI service returned error response (status: ${response.status})${errorCodeMsg}: ` +
(typeof response.body === 'string'
? response.body
: JSON.stringify(response.body)));
}
const modelResponse = response.body.choices[0].message.content;
// Set outputs for other workflow steps to use
Generated Vendored
+1 -1
View File
File diff suppressed because one or more lines are too long
+20 -5
View File
@@ -82,14 +82,29 @@ export async function run(): Promise<void> {
})
if (isUnexpected(response)) {
if (response.body.error) {
// Extract x-ms-error-code from headers if available
const errorCode = response.headers['x-ms-error-code']
const errorCodeMsg = errorCode ? ` (error code: ${errorCode})` : ''
// Check if response body exists and contains error details
if (response.body && response.body.error) {
throw response.body.error
}
// Handle case where response body is missing
if (!response.body) {
throw new Error(
`Failed to get response from AI service (status: ${response.status})${errorCodeMsg}. ` +
'Please check network connection and endpoint configuration.'
)
}
// Handle other error cases
throw new Error(
'An error occurred while fetching the response (' +
response.status +
'): ' +
response.body
`AI service returned error response (status: ${response.status})${errorCodeMsg}: ` +
(typeof response.body === 'string'
? response.body
: JSON.stringify(response.body))
)
}