mirror of
https://github.com/pockethost/pockethost.git
synced 2025-09-16 13:40:13 +00:00
enh(pockethost): Improve tryFetch by accepting node-fetch params
This commit is contained in:
parent
22ea7a9b1c
commit
40bbb3c774
5
.changeset/1719705901553.md
Normal file
5
.changeset/1719705901553.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
'pockethost': minor
|
||||
---
|
||||
|
||||
Improve tryFetch by accepting node-fetch params
|
@ -1,4 +1,4 @@
|
||||
import fetch, { Response } from 'node-fetch'
|
||||
import fetch, { RequestInit, Response } from 'node-fetch'
|
||||
import { LoggerService } from '../common'
|
||||
|
||||
export const TRYFETCH_RETRY_MS = 50
|
||||
@ -6,7 +6,7 @@ export const TRYFETCH_RETRY_MS = 50
|
||||
export type TryFetchConfig = {
|
||||
preflight: () => Promise<boolean>
|
||||
retryMs: number
|
||||
}
|
||||
} & RequestInit
|
||||
|
||||
/**
|
||||
* @param url The URL to fetch
|
||||
@ -53,7 +53,10 @@ export const tryFetch = async (
|
||||
}
|
||||
try {
|
||||
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`)
|
||||
resolve(res)
|
||||
} catch (e) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user