mirror of
https://github.com/Frooodle/Stirling-PDF.git
synced 2026-02-01 20:10:35 +01:00
- 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.
33 lines
933 B
TypeScript
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;
|
|
};
|
|
}; |