0

What do I have to do to make this work? I've proven the GET is returning successfully and I'm receiving the res.body I'm expecting.

But of course x is 'undefined' because the call to getSometing() isn't going to wait on requestify()

var x = getSomething();

function getSomething() {
    requestify.get('url')
        .then(function res) {
            return(res.body);
        })
        .fail(function err) {
            return("something happened");
        });
}
user5903880
  • 102
  • 8

1 Answers1

0

I went with:

var x = getSomething();

function getSomething() {
    return new Promise(resolve => {
        requestify.get('url')
            .then(function res) {
                resolve(res.body);
            })
            .fail(function err) {
                resolve("something happened");
            });
    });
}

This guarantees x will have something; rain or shine; and that is exactly what I want.

user5903880
  • 102
  • 8