feat: Enhance HaloClient with retry logic and improve error handling

- Added retry options to HaloClient for handling transient errors.
- Refactored request methods in HaloClient to utilize retry logic.
- Updated HaloService to include logging for error handling.
- Introduced ApiPaths utility for managing API endpoints.
- Implemented logger utility for consistent logging across services.
- Added tests for ContentService, Error handling, and TaxonomyService.
- Created retry utility for managing retry logic with exponential backoff.
- Updated types to include additional properties for better API response handling.
This commit is contained in:
2026-04-28 18:01:26 +08:00
parent b7f6288492
commit 12a7aebeff
18 changed files with 1573 additions and 815 deletions
+5 -3
View File
@@ -1,5 +1,7 @@
import type { TFile, Vault } from "obsidian";
import { requestUrl } from "obsidian";
import { logger } from "../utils/logger";
import { ApiPaths } from "../utils/api-paths";
export default class ImageUploader {
private readonly siteUrl: string;
@@ -37,7 +39,7 @@ export default class ImageUploader {
const file = vault.getAbstractFileByPath(normalizedPath);
if (!file || !(file instanceof TFile)) {
console.error(`[ImageUploader] 文件不存在或不是有效文件: ${normalizedPath}`);
logger.error("ImageUploader", `文件不存在或不是有效文件: ${normalizedPath}`);
return null;
}
@@ -54,7 +56,7 @@ export default class ImageUploader {
body += `\r\n--${boundary}--\r\n`;
const response = await requestUrl({
url: `${this.siteUrl}/apis/api.console.halo.run/v1alpha1/attachments/upload`,
url: `${this.siteUrl}${ApiPaths.attachments.upload()}`,
method: "POST",
headers: {
...this.headers,
@@ -72,7 +74,7 @@ export default class ImageUploader {
return null;
} catch (error) {
console.error(`[ImageUploader] 上传图片失败: ${filePath}`, error);
logger.error("ImageUploader", `上传图片失败: ${filePath}`, error);
return null;
}
}