```
const dbConnection = require("../dbConnection");    

var task = function () {
    var response = "";
    dbConnection.then(function () {
        //do something here
        response = "some value";            
    })
    .catch(function () {
       response = new Error("could not connect to DB");
    });

    //I can't return response here because the promise is not yet resolved/rejected.
}

```

I'm using a node module that someone else wrote. It returns a promise. I want to return either a string or a `new Error()` depending on whether the Promise object returned by the module resolved or not. How can I do this?

I can't return inside the `finally()` callback either because that `return` would apply to the callback function not my `task` function.