lib(renderer): add safeJson helper; migrate 6 JSON.parse try/catch call sites
This commit is contained in:
1 parent
a07b42e493
commit
be0ff5a041
8 files changed
+46
-48
No files matched your search
@@ -0,0 +1,8 @@
|
||||
export function safeJson<T>(text: string | null | undefined, fallback: T): T {
|
||||
if (text == null || text === "") return fallback;
|
||||
try {
|
||||
return JSON.parse(text) as T;
|
||||
} catch {
|
||||
return fallback;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user