async function fetchData() {
const [error, response] = await fetch('https://jsonplaceholder.typicode.com/todos/1')
if (error) {
console.log(error);
return
}
const [e, data] = await response.json()
if (e) {
console.log(e);
return
}
return data
}
fetchData()
I came across a LinkedIn post showing this it the new way to represents async/await without using try-catch block, is this right correct me if its wrong. its not working for me.
2
Answers
I’ve been using this workaround to avoid
try/catch
its like error first callback, but it make sense to usetry/catch
..catch
like this:await-to-js