I use the following code to get data from the server, sometimes return a Promise object, sometimes return a json object, how can I write to ensure that I must return a json object?
postFromServer ( requestParam ) {
const _self = this;
let url = requestParam["url"] || "";
let headers = requestParam["headers"] || "";
let postBody = requestParam["postBody"] || "";
let code = requestParam["code"] || 200;
let consoleMessage = requestParam["consoleMessage"] || false;
let response = _self.sendToServer( url, "POST", headers, postBody );
return response.then(function(value) {
if ( consoleMessage === true ) {
console.log("common-helper-es6 postFromServer === ", value)
}
return value;
}, function(error) {
console.log("postFromServer error === ", error)
});
},