const url = 'https://jsonplaceh'
function getAccess(url) {
return fetch(url).then(data => data.json()).catch(err => err)
}
async function userLogin() {
const result = await getAccess(url)
console.log(result)
}
[object Error] { ... }
const url = 'https://jsonplaceholder.typicode.com'
const result = new Promise((resolve, reject) => { console.log('main'); resolve('main 1'); })
.then(() => fetch(url)).then(data => data.json())
.then((resolve, reject) => {
resolve('data') // как тут вывести данные из предыдущего промиса, если он успешен?
reject('hello') // почему здесь не сработал reject и как его здесь обыграть, чтобы не дошло до catch?
})
.then((d) => { console.log('then'); throw Error(d); })
.catch((d) => { console.log('catch 1'); return `${d}, catch 1`; })
console.log(result)
catch
это .then((data,err) => err)
?new Promise().then(data => data).then(data => data).then((data,err) => return err).then(data => data)