JavaScript Node.js Basics Handling Errors in Node Handling Errors in Node

Failed on task 3 of 3 even I call the console.error in error callback

I tried request.on('error', error => { console.error('${error.message}'); });

or

request.on('error', error => console.error('${error.message}'));

and it just don'e let me pass with bummer "You didn't call console.error in the error callback."

app.js
const https = require("https");

const request = https.get("https://teamtreehouse.com/chalkers.json", response => {
  console.log(response.statusCode);
});

request.on('error', error => {
    console.error('${error.message}');
    });

1 Answer

Steven Parker
Steven Parker
203,716 Points

The error.message is already a string.

You don't need to do anything to convert it. Just pass it as an argument to the log function:

    console.error(error.message);