As someone who tries to write as little JavaScript as possible, I'm not sure I'm looking forward to infinite chains of impossible-to-debug promises any more than I currently enjoy infinite chains of impossible-to-debug callbacks.
Thanks for taking time to leave a comment, what part of a Promise Chain are you finding impossible to debug? Promises offer a second failed function within a then or the use of a catch to manage errors. Maybe I can help clear up some confusion.
In my opinion a promise chain is relief from callback hell.
I've not actually tried using them yet, but my comment mostly comes from looking at that chain, imagining a longer one, and then imagining trying to work out which .then and .catch happen at which level, much like trying to work out which level of }) } } }) ) }, }; } } }) the problem is in with callback hell.
I guess it should at least be easier to add good error reporting in the .catch blocks.
I recommend trying promises out, start by working with promises before creating them. A promise that you could work with is the fetch api for example, google has a good introduction
constgetJson=res=>{// comment out the if to return the error // and see how catch worksif(res.status!==200){returnnewError(`StatusCode: ${res.status}`)}returnres.json()}constgetUrl=url=>fetch(url).then(getJson)getUrl('https://baconipsum.com/api/?type=meat-and-filler').then(res=>console.log(res)).catch(err=>console.error(err.message))
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
As someone who tries to write as little JavaScript as possible, I'm not sure I'm looking forward to infinite chains of impossible-to-debug promises any more than I currently enjoy infinite chains of impossible-to-debug callbacks.
Hey Ian,
Thanks for taking time to leave a comment, what part of a Promise Chain are you finding impossible to debug? Promises offer a second
failed
function within athen
or the use of acatch
to manage errors. Maybe I can help clear up some confusion.In my opinion a promise chain is relief from callback hell.
I've not actually tried using them yet, but my comment mostly comes from looking at that chain, imagining a longer one, and then imagining trying to work out which
.then
and.catch
happen at which level, much like trying to work out which level of}) } } }) ) }, }; } } })
the problem is in with callback hell.I guess it should at least be easier to add good error reporting in the
.catch
blocks.I recommend trying promises out, start by working with promises before creating them. A promise that you could work with is the fetch api for example, google has a good introduction