fix(server): 4xx error property is optional (#12595)

close CLOUD-223

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->

## Summary by CodeRabbit

- **Bug Fixes**
  - Improved error handling for search requests to prevent issues when error details are missing, ensuring clearer fallback messages for unknown errors.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
fengmk2
2025-05-28 07:50:05 +00:00
parent eb49ffaedb
commit 274319dd6c

View File

@@ -274,15 +274,17 @@ export class ElasticsearchProvider extends SearchProvider {
`request failed, url: ${url}, body: ${body}, response status: ${response.status}, response body: ${JSON.stringify(data, null, 2)}`
);
const errorData = data as {
error: { type: string; reason: string } | string;
error?: { type: string; reason: string } | string;
};
let reason = '';
let type = '';
if (typeof errorData.error === 'string') {
reason = errorData.error;
} else {
} else if (errorData.error) {
reason = errorData.error.reason;
type = errorData.error.type;
} else {
reason = `unknown error, status ${response.status}, please check the response body`;
}
throw new InvalidSearchProviderRequest({
reason,