*Properly handle RPC errors

This commit is contained in:
Derrick Hammer 2022-08-30 22:25:44 -04:00
parent 599a1a1e0b
commit 33f5d36aca
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 17 additions and 8 deletions

View File

@ -13,7 +13,9 @@ import {
ensureUniqueRecords,
DNSRecord,
getTld,
resolverError,
} from "@lumeweb/libresolver";
import { RPCResponse } from "@lumeweb/relay-types";
const HIP5_EXTENSIONS = ["eth", "_eth"];
@ -24,6 +26,12 @@ interface HnsRecord {
ns: string;
}
interface HandshakeRPCResponse extends RPCResponse {
data?: {
records: HnsRecord[];
};
}
export default class Handshake extends AbstractResolverModule {
private async buildBlacklist(): Promise<Set<string>> {
const blacklist = new Set<string>();
@ -66,13 +74,17 @@ export default class Handshake extends AbstractResolverModule {
}
const chainRecords = await this.query(tld, bypassCache);
if (!chainRecords) {
if (chainRecords.error) {
return resolverError(chainRecords.error);
}
if (!chainRecords.data?.records.length) {
return resolverEmptyResponse();
}
let records: DNSRecord[] = [];
for (const record of chainRecords as HnsRecord[]) {
for (const record of chainRecords.data?.records) {
switch (record.type) {
case "NS": {
await this.processNs(
@ -260,17 +272,14 @@ export default class Handshake extends AbstractResolverModule {
private async query(
tld: string,
bypassCache: boolean
): Promise<[] | boolean> {
const query = this.resolver.rpcNetwork.wisdomQuery(
): Promise<HandshakeRPCResponse> {
let query = this.resolver.rpcNetwork.wisdomQuery(
"getnameresource",
"handshake",
[tld],
bypassCache
);
const resp = await query.result;
// @ts-ignore
return resp?.records || [];
return (await query.result) as HandshakeRPCResponse;
}
private async processTxt(