I have 2 async functions - one gets ids of towns, and the second one takes these ids and gets {towns} objects. I am importing an API which is also async.
The first function works fine, but the second one returns
LOG catchTowns [Error: Not found]
code:
import { getTown, getTownIds } from "./api/towns"
//getting IDs from API
const getTownIdsAsync = async () => {
const asyncids = await getTownIds()
return(asyncids.ids)
}
let idcka = new Promise((resolve, reject) => {
resolve(getTownIdsAsync())
})
.then(result => {
idcka = result
for(i=0; i < idcka.length; i++){
}
})
.catch(err => {
console.log('catchIdcka', err)
})
//getting Towns from API
const getTownsByIdsAsync = async (ajdycka) => {
const asyncTowns = await getTown(ajdycka)
return(asyncTowns)
}
let towns = new Promise((resolve, reject) => {
resolve(getTownsByIdsAsync())
})
.then(result => {
towns = result
console.log(towns)
})
.catch(err => {
console.log('catchTowns', err)
})
Via Active questions tagged javascript - Stack Overflow https://ift.tt/FoRM2K3
Comments
Post a Comment