Type caught errors as unknown in the frontend
Replace `catch (e: any)` with `catch (e)` and read the message through a new errorMessage() helper. ApiError.data gets a real type, and useDismissingState's setter keeps one identity across renders. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -25,3 +25,11 @@ export function truncateText(text: string, maxLength: number): string {
|
||||
if (text.length <= maxLength) return text
|
||||
return `${text.slice(0, maxLength)}...`
|
||||
}
|
||||
|
||||
// Message from a caught value (an Error, an ApiError, or anything thrown), or undefined when
|
||||
// it has none — so callers can write `errorMessage(e) || "Fallback text"`.
|
||||
export function errorMessage(e: unknown): string | undefined {
|
||||
if (e instanceof Error) return e.message || undefined
|
||||
if (typeof e === "object" && e !== null && "message" in e && typeof e.message === "string") return e.message || undefined
|
||||
return undefined
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user