This commit is contained in:
Naoki Ainoya
2025-07-02 09:47:42 +09:00
parent 37fe8eb685
commit dee5a5edef

View File

@@ -85,24 +85,26 @@ export async function run(): Promise<void> {
// 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.'
'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))
(typeof response.body === 'string'
? response.body
: JSON.stringify(response.body))
)
}