mirror of
https://github.com/haexhub/haex-hub.git
synced 2025-12-16 22:20:51 +01:00
- Add SerializedExtensionError TypeScript bindings from Rust - Add ExtensionErrorCode enum export with ts-rs - Create useExtensionError composable with type guards and error message extraction - Fix developer page toast messages to show proper error messages instead of [object Object] - Add getErrorMessage helper function for robust error handling across different error types 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
44 lines
897 B
TypeScript
44 lines
897 B
TypeScript
import type { SerializedExtensionError } from '~~/src-tauri/bindings/SerializedExtensionError'
|
|
|
|
/**
|
|
* Type guard to check if error is a SerializedExtensionError
|
|
*/
|
|
export function isSerializedExtensionError(error: unknown): error is SerializedExtensionError {
|
|
return (
|
|
typeof error === 'object' &&
|
|
error !== null &&
|
|
'code' in error &&
|
|
'message' in error &&
|
|
'type' in error
|
|
)
|
|
}
|
|
|
|
/**
|
|
* Extract error message from unknown error type
|
|
*/
|
|
export function getErrorMessage(error: unknown): string {
|
|
if (isSerializedExtensionError(error)) {
|
|
return error.message
|
|
}
|
|
|
|
if (error instanceof Error) {
|
|
return error.message
|
|
}
|
|
|
|
if (typeof error === 'string') {
|
|
return error
|
|
}
|
|
|
|
return String(error)
|
|
}
|
|
|
|
/**
|
|
* Composable for handling extension errors
|
|
*/
|
|
export function useExtensionError() {
|
|
return {
|
|
isSerializedExtensionError,
|
|
getErrorMessage,
|
|
}
|
|
}
|