**feat: implement robust error-handling and operation utilities for storage adapters**
- Added `BrainyError` class to classify and handle errors with types like `TIMEOUT`, `NETWORK`, `STORAGE`, `NOT_FOUND`, and `RETRY_EXHAUSTED`. Includes static helper methods for error creation and retry determination. - Introduced `operationUtils` with utility functions for timeout, retry logic, and exponential backoff. Implements features like `withTimeout`, `withRetry`, and a combined `withTimeoutAndRetry`. - Updated `S3CompatibleStorage` to leverage new operation utilities for timeout and retry handling, including `StorageOperationExecutors` for clean operation execution. - Enhanced `storageFactory` to pass `OperationConfig` for configurable timeout and retry behavior. - Extended `BrainyData` to include timeout and retry policy configuration at initialization. **Purpose**: Improve storage reliability by introducing configurable and reusable error-handling and operation utilities, reducing code duplication and enhancing maintainability.
This commit is contained in:
parent
db67ccd34f
commit
e8127c54a5
5 changed files with 516 additions and 54 deletions
|
|
@ -9,6 +9,7 @@ import {OPFSStorage} from './adapters/opfsStorage.js'
|
|||
import {S3CompatibleStorage, R2Storage} from './adapters/s3CompatibleStorage.js'
|
||||
import {FileSystemStorage} from './adapters/fileSystemStorage.js'
|
||||
import {isBrowser} from '../utils/environment.js'
|
||||
import {OperationConfig} from '../utils/operationUtils.js'
|
||||
|
||||
/**
|
||||
* Options for creating a storage adapter
|
||||
|
|
@ -165,6 +166,11 @@ export interface StorageOptions {
|
|||
*/
|
||||
serviceType?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* Operation configuration for timeout and retry behavior
|
||||
*/
|
||||
operationConfig?: OperationConfig
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -238,7 +244,8 @@ export async function createStorage(
|
|||
accessKeyId: options.s3Storage.accessKeyId,
|
||||
secretAccessKey: options.s3Storage.secretAccessKey,
|
||||
sessionToken: options.s3Storage.sessionToken,
|
||||
serviceType: 's3'
|
||||
serviceType: 's3',
|
||||
operationConfig: options.operationConfig
|
||||
})
|
||||
} else {
|
||||
console.warn('S3 storage configuration is missing, falling back to memory storage')
|
||||
|
|
|
|||
Reference in a new issue