Stirling-PDF/frontend/src/utils/toolErrorHandler.ts
Reece Browne dcadada7d3 feat: Implement shared hooks for tool operations
- Introduced `useToolApiCalls` for handling API calls with file processing and cancellation support.
- Created `useToolOperation` to manage tool operations, including state management, error handling, and file processing.
- Added `useToolResources` for managing blob URLs and generating thumbnails.
- Developed `useToolState` for centralized state management of tool operations.
- Refactored `useSplitOperation` to utilize the new shared hooks, simplifying the execution of split operations.
- Updated `useSplitParameters` to remove mode state and integrate with the new parameter structure.
- Enhanced error handling with `toolErrorHandler` utilities for standardized error extraction and messaging.
- Implemented `toolOperationTracker` for creating operation tracking data for file context integration.
- Added `toolResponseProcessor` for processing API response blobs based on handler configuration.
2025-08-04 11:59:32 +01:00

33 lines
933 B
TypeScript

/**
* Standardized error handling utilities for tool operations
*/
/**
* Default error extractor that follows the standard pattern
*/
export const extractErrorMessage = (error: any): string => {
if (error.response?.data && typeof error.response.data === 'string') {
return error.response.data;
}
if (error.message) {
return error.message;
}
return 'Operation failed';
};
/**
* Creates a standardized error handler for tool operations
* @param fallbackMessage - Message to show when no specific error can be extracted
* @returns Error handler function that follows the standard pattern
*/
export const createStandardErrorHandler = (fallbackMessage: string) => {
return (error: any): string => {
if (error.response?.data && typeof error.response.data === 'string') {
return error.response.data;
}
if (error.message) {
return error.message;
}
return fallbackMessage;
};
};