*Return ERR_NOT_READY rejection error if chain is not synced yet

This commit is contained in:
Derrick Hammer 2022-07-23 02:45:50 -04:00
parent b640084920
commit b01ea298b7
1 changed files with 15 additions and 1 deletions

View File

@ -5,6 +5,7 @@ import rand from "random-key";
import SPVNode from "hsd/lib/node/spvnode.js"; import SPVNode from "hsd/lib/node/spvnode.js";
import config from "../config.js"; import config from "../config.js";
import { createRequire } from "module"; import { createRequire } from "module";
import { ERR_NOT_READY } from "../error.js";
const require = createRequire(import.meta.url); const require = createRequire(import.meta.url);
const { NodeClient } = require("hs-client"); const { NodeClient } = require("hs-client");
@ -80,6 +81,19 @@ export default {
throw new Error("Invalid Chain"); throw new Error("Invalid Chain");
} }
return await hnsClient.execute("getnameresource", args); let resp;
try {
resp = await hnsClient.execute("getnameresource", args);
} catch (e: any) {
e = e as Error;
const eType = e.type.toLowerCase();
const eMessage = e.message.toLowerCase();
if (eType === "rpcerror" && eMessage.includes("chain is not synced")) {
return Promise.reject({ ...e, message: ERR_NOT_READY });
}
}
return resp;
}, },
} as RpcMethodList; } as RpcMethodList;