mirror of
https://github.com/tooot-app/app
synced 2025-01-21 21:35:34 +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) {
|
||||
setGlobalStorage('accounts', (accounts || []).concat([accountKey]))
|
||||
}
|
||||
setAccount(accountKey)
|
||||
await setAccount(accountKey)
|
||||
|
||||
goBack && navigation.goBack()
|
||||
}
|
||||
|
@ -33,9 +33,13 @@ export const getGlobalStorage = {
|
||||
object: <T extends keyof StorageGlobal>(key: T) => {
|
||||
const value = storage.global.getString(key)
|
||||
if (value?.length) {
|
||||
return JSON.parse(value) as NonNullable<StorageGlobal[T]> extends object
|
||||
? StorageGlobal[T]
|
||||
: never
|
||||
try {
|
||||
return JSON.parse(value) as NonNullable<StorageGlobal[T]> extends object
|
||||
? StorageGlobal[T]
|
||||
: never
|
||||
} catch {
|
||||
return undefined
|
||||
}
|
||||
} else {
|
||||
return undefined
|
||||
}
|
||||
@ -108,9 +112,13 @@ export const getAccountStorage = {
|
||||
object: <T extends keyof StorageAccount>(key: T) => {
|
||||
const value = storage.account?.getString(key)
|
||||
if (value?.length) {
|
||||
return JSON.parse(value) as NonNullable<StorageAccount[T]> extends object
|
||||
? StorageAccount[T]
|
||||
: never
|
||||
try {
|
||||
return JSON.parse(value) as NonNullable<StorageAccount[T]> extends object
|
||||
? StorageAccount[T]
|
||||
: never
|
||||
} catch {
|
||||
return undefined
|
||||
}
|
||||
} else {
|
||||
return undefined
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user