mirror of
https://github.com/tooot-app/app
synced 2025-02-01 19:16:56 +01:00
Catch potentially json parsing error
This commit is contained in:
parent
5d3f773a2a
commit
e60535cd1c
@ -186,7 +186,7 @@ const ComponentInstance: React.FC<Props> = ({
|
|||||||
if (!account) {
|
if (!account) {
|
||||||
setGlobalStorage('accounts', (accounts || []).concat([accountKey]))
|
setGlobalStorage('accounts', (accounts || []).concat([accountKey]))
|
||||||
}
|
}
|
||||||
setAccount(accountKey)
|
await setAccount(accountKey)
|
||||||
|
|
||||||
goBack && navigation.goBack()
|
goBack && navigation.goBack()
|
||||||
}
|
}
|
||||||
|
@ -33,9 +33,13 @@ export const getGlobalStorage = {
|
|||||||
object: <T extends keyof StorageGlobal>(key: T) => {
|
object: <T extends keyof StorageGlobal>(key: T) => {
|
||||||
const value = storage.global.getString(key)
|
const value = storage.global.getString(key)
|
||||||
if (value?.length) {
|
if (value?.length) {
|
||||||
|
try {
|
||||||
return JSON.parse(value) as NonNullable<StorageGlobal[T]> extends object
|
return JSON.parse(value) as NonNullable<StorageGlobal[T]> extends object
|
||||||
? StorageGlobal[T]
|
? StorageGlobal[T]
|
||||||
: never
|
: never
|
||||||
|
} catch {
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
@ -108,9 +112,13 @@ export const getAccountStorage = {
|
|||||||
object: <T extends keyof StorageAccount>(key: T) => {
|
object: <T extends keyof StorageAccount>(key: T) => {
|
||||||
const value = storage.account?.getString(key)
|
const value = storage.account?.getString(key)
|
||||||
if (value?.length) {
|
if (value?.length) {
|
||||||
|
try {
|
||||||
return JSON.parse(value) as NonNullable<StorageAccount[T]> extends object
|
return JSON.parse(value) as NonNullable<StorageAccount[T]> extends object
|
||||||
? StorageAccount[T]
|
? StorageAccount[T]
|
||||||
: never
|
: never
|
||||||
|
} catch {
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user