17 lines
553 B
TypeScript
17 lines
553 B
TypeScript
/**
|
|
* Extract user-facing error message from various error formats.
|
|
* Supports: Error objects, Tauri AppError { kind, message }, and plain strings.
|
|
*/
|
|
export function cleanErrorMessage(error: unknown): string {
|
|
if (error instanceof Error) {
|
|
return error.message;
|
|
}
|
|
if (typeof error === 'object' && error !== null && 'message' in error) {
|
|
return String((error as { message: string }).message);
|
|
}
|
|
if (typeof error === 'string') {
|
|
return error;
|
|
}
|
|
return 'An unknown error occurred';
|
|
}
|