enh(pockethost): Improve tryFetch by accepting node-fetch params

This commit is contained in:
Ben Allfree 2024-06-29 17:05:01 -07:00
parent 22ea7a9b1c
commit 40bbb3c774
2 changed files with 11 additions and 3 deletions

View File

@ -0,0 +1,5 @@
---
'pockethost': minor
---
Improve tryFetch by accepting node-fetch params

View File

@ -1,4 +1,4 @@
import fetch, { Response } from 'node-fetch' import fetch, { RequestInit, Response } from 'node-fetch'
import { LoggerService } from '../common' import { LoggerService } from '../common'
export const TRYFETCH_RETRY_MS = 50 export const TRYFETCH_RETRY_MS = 50
@ -6,7 +6,7 @@ export const TRYFETCH_RETRY_MS = 50
export type TryFetchConfig = { export type TryFetchConfig = {
preflight: () => Promise<boolean> preflight: () => Promise<boolean>
retryMs: number retryMs: number
} } & RequestInit
/** /**
* @param url The URL to fetch * @param url The URL to fetch
@ -53,7 +53,10 @@ export const tryFetch = async (
} }
try { try {
dbg(`Fetch: START`) dbg(`Fetch: START`)
const res = await fetch(url, { signal: AbortSignal.timeout(500) }) const res = await fetch(url, {
...config,
signal: AbortSignal.timeout(500),
})
dbg(`Fetch: SUCCESS`) dbg(`Fetch: SUCCESS`)
resolve(res) resolve(res)
} catch (e) { } catch (e) {