I wanted to make a function that responds to a HTTP Request and that would call another function, which would give that function a value that it sends back as a responds. To do that, I used a promise. However, each time I do an HTTP Post to InternalBot, the server sends nothing back. All my other HTTP functions, that don’t rely on a separate promise functions, work fine. Does anybody have an idea what the problem could be?
Below is the code that I used.
import {
response,
ok,
notFound,
serverError
} from 'wix-http-functions';
import wixData from 'wix-data';
export function post_InternalBot(request) {
Calculation()
.then(function check (data1){
let options = {
status: 200,
body: {
"fulfillmentText": data1,
},
headers: {
"Content-Type": "application/json"
}
};
return response(options);
})
.catch(function check (err1){
let options1 = {
status: 200,
body: {
"fulfillmentText": err1,
},
headers: {
"Content-Type": "application/json"
}
};
return response(options1);
})
}
function Calculation() {
let total_bought = 1;
var promise = new Promise(function check (resolve, reject) {
if (total_bought === 1) {
resolve(total_bought);
}
if (total_bought !== 1) {
let message = ("There was a problem.")
reject(message);
}
});
return promise;
}