D3.json method, what is wrong here?

I’m reading from multiple sources that this should be the correct way to handle errors and data when using the d3.json() method:

const url="https://raw.githubusercontent.com/freeCodeCamp/ProjectReferenceData/master/GDP-data.json";

d3.json(url, function(error, json) {
    console.log(error, json)
});

However, nothing shows up in my console, nor the data, nor the error (if I change the url to something that doesn’t exist).
I also see that this syntax is used in the FCC D3 Scatter Plot project example, but it looks like it doesn’t really catch any error.

Instead, this code works as expected:

d3.json(url).then(json => console.log(json))
            .catch(error => {
    if (error) {
        console.warn(error)
    }
});

Am I missing something obvious?
Thanks

I found a the reason for this in a stackoverflow post, in case anyone is interested.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.