mirror of
https://github.com/andy-stack/vaultkeeper-ai.git
synced 2026-07-22 06:42:03 +00:00
refactor: improve type safety in file service and error handling
- Change listFiles() to synchronous method returning cached IDs - Add type predicate to ApiError.isApiError() for better type narrowing - Remove redundant ApiError union type in retry error handling
This commit is contained in:
parent
3e013f6c9f
commit
e4f56e3877
3 changed files with 4 additions and 4 deletions
|
|
@ -35,7 +35,7 @@ export abstract class BaseAIFileService implements IAIFileService {
|
|||
this.fileIDs = await this.listFilesFromAPI();
|
||||
}
|
||||
|
||||
public async listFiles(): Promise<string[]> {
|
||||
public listFiles(): string[] {
|
||||
return [...this.fileIDs];
|
||||
}
|
||||
|
||||
|
|
@ -78,7 +78,7 @@ export abstract class BaseAIFileService implements IAIFileService {
|
|||
|
||||
// Retries operation on retryable errors (500, 502, 503, 504) with exponential backoff
|
||||
protected async withRetry<T>(operationName: string, operation: () => Promise<T>): Promise<T> {
|
||||
let lastError: ApiError | unknown;
|
||||
let lastError: unknown;
|
||||
|
||||
for (let attempt = 1; attempt <= BaseAIFileService.MAX_RETRIES; attempt++) {
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import type { Attachment } from "Conversations/Attachment";
|
|||
|
||||
export interface IAIFileService {
|
||||
refreshCache(): Promise<void>;
|
||||
listFiles(): Promise<string[]>;
|
||||
listFiles(): string[];
|
||||
uploadFile(attachment: Attachment): Promise<string>;
|
||||
deleteFile(attachment: Attachment): Promise<void>;
|
||||
}
|
||||
|
|
@ -23,7 +23,7 @@ export class ApiError extends Error {
|
|||
this.name = "ApiError";
|
||||
}
|
||||
|
||||
static isApiError(error: unknown): boolean {
|
||||
static isApiError(error: unknown): error is ApiError {
|
||||
return error instanceof ApiError;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue