mirror of
https://github.com/pockethost/pockethost.git
synced 2025-05-19 13:26:42 +00:00
fix: handle preflight exceptions in tryCatch
This commit is contained in:
parent
d623ed373a
commit
4797706605
@ -1,5 +1,6 @@
|
|||||||
import { Logger, safeCatch } from '@pockethost/common'
|
import { Logger, safeCatch } from '@pockethost/common'
|
||||||
|
|
||||||
|
const TRYFETCH_RETRY_MS = 50
|
||||||
export const tryFetch = (logger: Logger) =>
|
export const tryFetch = (logger: Logger) =>
|
||||||
safeCatch(
|
safeCatch(
|
||||||
`tryFetch`,
|
`tryFetch`,
|
||||||
@ -10,9 +11,14 @@ export const tryFetch = (logger: Logger) =>
|
|||||||
const tryFetch = async () => {
|
const tryFetch = async () => {
|
||||||
if (preflight) {
|
if (preflight) {
|
||||||
dbg(`Checking preflight`)
|
dbg(`Checking preflight`)
|
||||||
const shouldFetch = await preflight()
|
try {
|
||||||
if (!shouldFetch) {
|
const shouldFetch = await preflight()
|
||||||
reject(new Error(`tryFetch failed preflight, aborting`))
|
if (!shouldFetch) {
|
||||||
|
reject(new Error(`failed preflight, aborting`))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
reject(new Error(`preflight threw error, aborting`))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -22,8 +28,10 @@ export const tryFetch = (logger: Logger) =>
|
|||||||
dbg(`Fetch ${url} successful`)
|
dbg(`Fetch ${url} successful`)
|
||||||
resolve()
|
resolve()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
dbg(`Could not fetch ${url}, trying again in 1s`)
|
dbg(
|
||||||
setTimeout(tryFetch, 1000)
|
`Could not fetch ${url}, trying again in ${TRYFETCH_RETRY_MS}ms. Raw error ${e}`
|
||||||
|
)
|
||||||
|
setTimeout(tryFetch, TRYFETCH_RETRY_MS)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tryFetch()
|
tryFetch()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user