-
-
Notifications
You must be signed in to change notification settings - Fork 33k
Closed
Labels
fetchIssues and PRs related to the Fetch APIIssues and PRs related to the Fetch API
Description
Version
19.3.0
Platform
Microsoft Windows NT 10.0.22000.0 x64
Subsystem
No response
What steps will reproduce the bug?
let url = "https://cdn.jsdelivr.net/gh/fawazahmed0/currency-api@1/"
let dateValue = 'latest'
async function begin(){
let data = await fetch(`${url}/${dateValue}/currencies.json`).then(res => res.json())
}
begin()
How often does it reproduce? Is there a required condition?
No response
What is the expected behavior?
No response
What do you see instead?
node:internal/deps/undici/undici:14062
Error.captureStackTrace(err, this);
^
TypeError: fetch failed
at Object.fetch (node:internal/deps/undici/undici:14062:11)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async begin (C:\Users\nawaz\Desktop\codetest\fec\cache-jsdelivr-api.js:12:20) {
cause: TypeError: Cannot read properties of undefined (reading 'reason')
at makeAppropriateNetworkError (node:internal/deps/undici/undici:6736:171)
at schemeFetch (node:internal/deps/undici/undici:13492:16)
at node:internal/deps/undici/undici:13422:26
at mainFetch (node:internal/deps/undici/undici:13439:11)
at httpRedirectFetch (node:internal/deps/undici/undici:13692:14)
at httpFetch (node:internal/deps/undici/undici:13638:28)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async schemeFetch (node:internal/deps/undici/undici:13546:18)
at async node:internal/deps/undici/undici:13422:20
at async mainFetch (node:internal/deps/undici/undici:13418:20)
}
Node.js v19.3.0
Additional information
The same code works fine in v18.12.1
If you are interested, here is my complete code:
// Fetch all latest & todays links to cache the data by jsdelivr
let url = "https://cdn.jsdelivr.net/gh/fawazahmed0/currency-api@1/"
let apiLinks = [url]
let extensions = [".min.json", ".json"]
async function begin() {
for (let dateValue of ['latest', new Date().toISOString().substring(0, 10)]) {
let data = await fetch(`${url}/${dateValue}/currencies.json`).then(res => res.json())
let currencies = Object.keys(data)
await multipleFetch(getURLs(`${url}/${dateValue}/currencies`))
for (let curr of currencies) {
let promiseHolder = []
promiseHolder.push(multipleFetch(getURLs(`${url}/${dateValue}/currencies/${curr}`)))
for (let curr2 of currencies)
promiseHolder.push(multipleFetch(getURLs(`${url}/${dateValue}/currencies/${curr}/${curr2}`)))
await Promise.allSettled(promiseHolder)
}
}
}
async function multipleFetch(links) {
for (let link of links)
await fetch(link, { method: 'HEAD' })
}
function getURLs(endpoint, links) {
links = links || apiLinks
return extensions.map(ext => links.map(e => e + endpoint + ext)).flat()
}
begin()
Glavin001 and abdullahquantumx
Metadata
Metadata
Assignees
Labels
fetchIssues and PRs related to the Fetch APIIssues and PRs related to the Fetch API