π© codes
The Callback hell
function hell() {
step1((result1) => {
step2((result2) => {
....
})
})
}
The Promise hell
hell()
.then(result => {
handle(result)
.then(anotherResult => {
...
})
.catch(error => {
...
})
})
.catch(error => {
})
β€οΈ Better codes
await step1().catch(handleError);
await step2().catch(handleError);
await step3().catch(handleError);
π My style
const getData = async (url) => {
try {
const data = await Prosime;
return [data, null];
} catch(error) {
console.log(error);
return [null, error];
}
}
const [data, error] = await (url);
Top comments (1)
Try catch block with async await is glorious. Good write up :)