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.
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