Promise chaining (.then, .catch)
Në shqip: Zinxhiri i premtimeve
ShpjegimiSQ
Çdo .then() kthen një promise të ri, kështu që i lidh hapat njërin pas tjetrit; .catch() kap gabimin nga cilido hap, dhe .finally() ekzekutohet gjithmonë. async/await është e njëjta gjë, më e lexueshme.
EnglishEN
Each .then() returns a new promise, so you chain steps one after another; .catch() catches an error from any step, and .finally() always runs. async/await is the same thing, more readable.
Si ta mendosh
Si një varg dominosh: çdo pjesë rrëzon tjetrën.
Lexoje në anglisht
Like a row of dominoes: each piece knocks over the next.
Shembull kodijavascript
fetch("/api/notat")
.then(r => r.json())
.then(notat => console.log(notat))
.catch(e => console.error(e));