DEV Community

Discussion on: Notes on ECMAScript 6 (ES6)

ikirker profile image
Ian Kirker

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.

Thread Thread
hardy613 profile image
Scott Hardy Author

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

const getJson = res => {
    // comment out the if to return the error 
    // and see how catch works
    if(res.status !== 200) {
        return new Error(`StatusCode: ${res.status}`)
    return res.json()
const getUrl = url => fetch(url).then(getJson)

    .then(res => console.log(res))
    .catch(err => console.error(err.message))