Best approach on handling function that returns either a promise or just synchronous code I wrote some code and I'm trying to get some feedback on it. I'll try to summerize the essential only. I have a function that based on a condition returns a promise or something else:

this.isActive = function(){
  if(this.disableApplePay &amp;&amp; window.ApplePaySession){
    return window.ApplePaySession.canMakePaymentsWithActiveCard(this.merchantId).then(function(response){
      return response;
    });
  }
  return !!(window.ApplePaySession &amp;&amp; window.ApplePaySession.canMakePayments() &amp;&amp;
    window.ApplePaySession.supportsVersion(3));
}


Then I call this function to check isActive() in another few methods like this:

Promise.resolve(this.isActive()).then(function(response){
  if(response){
    //execute code here
  }
});


Is the Promise.resolve() in this case following best practice? Is there a better way to deal with the isActive() function? 

PS: Let's exclude the async await for the sake of the above example please.
You really don't want a function sometimes returning a promise and sometimes returning a value.  That just makes it difficult for the caller.  Instead, if you sometimes have a promise to return, then you should always return a promise.  

function isActive(){
  if(condition){
    return API.someFunction().then(function(response){
      return response;
    });
  }
  return Promise.resolve(active);
}


Then, your caller can just know that it always returns a promise and they can code accordingly.  When you have complexity like this, it's better to encapsulate it in the function itself rather than make every single caller deal with it.

So, the caller can then always and consistently just do:

isActive().then(...).catch(...);




Also, if you actually have this in your real code:

   .then(function(response){
      return response;
    });


then, you can remove that entirely and just use this as it generates the exact same result, but is less code:

function isActive(){
  if(condition){
    return API.someFunction();
  }
  return Promise.resolve(active);
}


Both examples return a promise that resolves to response.  One is obviously a lot simpler than the other.