0

My await-async function looks like:

    try {
        // Use node-fetch to retrieve data from server
        var response = await fetch(url);
        var json = await response.json();

        // If "error" exists in the returned JSON, 
        // thrown a new Error with a detailed error message.
        // e.g. "Invalid user credentials"
        if(json.hasOwnProperty('error')){
            console.log("FLAG 0");
            var error_desc = json['error_description'];
            console.log("error_desc: ", error_desc);
            throw new Error(error_desc);
        }

        var access_token = json['access_token'];
        console.log("FLAG 1");
        return access_token;
    } catch (err) {
        console.log("FLAG 2", JSON.stringify(err));
        return JSON.stringify({ "Error": err });
    }

The issue was that I could reach FLAG 0 and FLAG 2 but no error message was printed. err remained empty.

This is what I got from the console output.

FLAG 0
error_desc:  Invalid user credentials
FLAG 2 {}
alextc
  • 3,206
  • 10
  • 63
  • 107

0 Answers0