How to set timeout, JsonRpc with node-fetch
junha-ahn opened this issue · 3 comments
junha-ahn commented
import { JsonRpc } from 'eosjs'
import fetch from 'node-fetch'
const rpc = new JsonRpc(url, { fetch }) // I can't set anything...
const result = await rpc.get_block(blockHeight)
I want to set timeout.
now I am setting timeout in node_modules dist file
junha-ahn commented
Ah, Actually, I can set right this.
new JsonRpc(url, {
fetch: (endpoint, options) => {
return fetch(endpoint, {
...options,
timeout: 1000 * 1
})
}
})
But, Isn't there a better way?
bradlhart commented
Your second response would be the recommended way to add options to fetch requests through eosjs. The reason why fetch options aren't available at the individual rpc functions is to have clearly defined required arguments for each function. If you need different options for some rpc functions, you can create multiple JsonRpc instances.
junha-ahn commented
I think it's not comfortable. Because I have to check the (eosjs module) code
But OK. Thank you.