Skip to content

Commit

Permalink
fix: fix ping logging
Browse files Browse the repository at this point in the history
  • Loading branch information
DiRaiks committed May 29, 2024
1 parent 9ea5861 commit de3599a
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/actions/ping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,38 @@ export const pingAction = async (

retryCount++
const url = `https://${cid}.ipfs.${endpoint}`
console.log(`${isTTY
logger.info(`${isTTY
? `${colors.bold(`[${retryCount}]`)}: Requesting content at ${url}`
: `[${retryCount}]`}: Requesting content at ${url}`,
)
try {
const response = await fetch(url, { signal: AbortSignal.timeout(timeout), redirect: 'follow' })
if (response.status === 504) {
if (retries > 1) {
console.log(`🔄 Retrying in ${retryInterval / 1000} seconds...`)
logger.info(`🔄 Retrying in ${retryInterval / 1000} seconds...`)
await new Promise(resolve => setTimeout(resolve, retryInterval))
return pingAction({ cid, endpoint, options: { maxRetries: retries - 1, retryInterval } })
}
else {
return console.error(gwOfflineMessage)
return logger.error(gwOfflineMessage)
}
}
else {
return console.log(`Gateway status: ${
return logger.info(`Gateway status: ${
response.status >= 200 && response.status < 400
? logger.info((isTTY ? colors.bold(colors.green(`Online ${response.status}`)) : `Online ${response.status}`))
? (isTTY ? colors.bold(colors.green(`Online ${response.status}`)) : `Online ${response.status}`)
: response.status
}`)
}
}
catch (error) {
if (error instanceof DOMException) {
if (retries > 1) {
console.log(`⌛ Timed out. Retrying...`)
logger.info(`⌛ Timed out. Retrying...`)
return pingAction({ cid, endpoint, options: { maxRetries: retries - 1, retryInterval } })
}
else {
return console.error(gwOfflineMessage)
return logger.error(gwOfflineMessage)
}
}
logger.error('Error fetching endpoint:', (error as Error).message)
Expand Down

0 comments on commit de3599a

Please sign in to comment.