mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-25 10:22:55 +08:00
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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user