Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion cmd/rpc/web/wallet/src/core/dsCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,27 @@ export async function fetchDsOnce<T=any>(chain: ChainLike, key: string, ctx?: Re
const { url, init } = buildRequest(chain, leaf, ctx)
if (!url) throw new Error(`Invalid DS url for key ${key}`)
const res = await fetch(url, init)
if (!res.ok) throw new Error(`RPC ${res.status}`)
if (!res.ok) {
const ct = res.headers.get('content-type') || ''
let response: any
try {
response = ct.includes('application/json') ? await res.json() : await res.text()
} catch {
response = undefined
}

const message =
response && typeof response === 'object' && 'msg' in response
? `RPC ${res.status}: ${response.msg}`
: `RPC ${res.status}`

throw Object.assign(new Error(message), {
status: res.status,
code: response && typeof response === 'object' ? response.code : undefined,
module: response && typeof response === 'object' ? response.module : undefined,
response,
})
}
const parsed = await parseResponse(res, leaf)
return parsed as T
}
Expand Down
13 changes: 12 additions & 1 deletion cmd/rpc/web/wallet/src/hooks/useNodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ export interface NodeData {
validatorSet: any;
}

const isNoValidatorsError = (error: unknown): boolean =>
typeof error === "object" &&
error !== null &&
"code" in error &&
Number((error as { code?: unknown }).code) === 29;

/**
* Hook to fetch the current chain's committeeId from admin.config
*/
Expand Down Expand Up @@ -156,7 +162,12 @@ export const useNodeData = (nodeId: string) => {
dsFetch("admin.consensusInfo"),
dsFetch("admin.peerInfo"),
dsFetch("admin.resourceUsage"),
dsFetch("validatorSet", { height: 0, committeeId: committeeId! }),
dsFetch("validatorSet", { height: 0, committeeId: committeeId! }).catch((error) => {
if (isNoValidatorsError(error)) {
return { validatorSet: [] };
}
throw error;
}),
]);

return {
Expand Down