mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-08-27 14:49:23 +00:00
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;
|
||
|
};
|
||
|
};
|