Merge pull request #89 from polkadot-api/vo/fix-storage-crash

fix: capture failed storage queries
This commit is contained in:
Victor Oliva
2025-10-17 10:23:53 +02:00
committed by GitHub
2 changed files with 30 additions and 1 deletions
@@ -100,6 +100,13 @@ const DecodedResultDisplay: FC<{
storageSubscription: StorageSubscription
subscriptionKey: string
}> = ({ storageSubscription, subscriptionKey }) => {
if ("error" in storageSubscription) {
return (
<div className="text-sm text-foreground/50">
{storageSubscription.error}
</div>
)
}
if (!("result" in storageSubscription)) {
return <div className="text-sm text-foreground/50">Loading…</div>
}
@@ -170,6 +177,14 @@ const DecodedResultDisplay: FC<{
const JsonResultDisplay: FC<{
storageSubscription: StorageSubscription
}> = ({ storageSubscription }) => {
if ("error" in storageSubscription) {
return (
<div className="text-sm text-foreground/50">
{storageSubscription.error}
</div>
)
}
if (!("result" in storageSubscription)) {
return <div className="text-sm text-foreground/50">Loading…</div>
}
+15 -1
View File
@@ -11,6 +11,7 @@ import {
} from "@react-rxjs/utils"
import { Binary } from "polkadot-api"
import {
catchError,
combineLatest,
concat,
distinctUntilChanged,
@@ -168,7 +169,8 @@ export type StorageSubscription = {
single: boolean
paused: boolean
completed: boolean
} & ({ result: unknown } | {})
} & ({ result: unknown } | { error: string } | {})
const [getStorageSubscription$, storageSubscriptionKeyChange$] = partitionByKey(
newStorageSubscription$,
() => uuid(),
@@ -198,6 +200,18 @@ const [getStorageSubscription$, storageSubscriptionKeyChange$] = partitionByKey(
paused,
completed,
})),
catchError((ex) => {
console.error(ex)
return [
{
...props,
paused: false,
completed: true,
error:
ex instanceof Error ? `Error: ${ex.message}` : "(Errored)",
} satisfies StorageSubscription,
]
}),
)
}),
takeUntil(merge(removeStorageSubscription$(id), selectedChainChanged$)),