I've this snippet code. In some point of this code, I can obtain response.send
... in other points, I obtain the error response.send is not a function
. Below I highlight in which points this happens:
router.post("/*", function (request, response) {
if (request.path === "/permissions") {
...
if (!error_json) {
(async () => {
var cookie = request.cookies['JSESSIONID'];
var user_cookie = "JSESSIONID=" + cookie;
var devices = [];
var number;
const response = await axios.get("http://10.10.0.145/api/devices", {
headers: {
'Cookie': user_cookie
}
})
for (let i = 0; i < response.data.length; i++) {
devices[i] = response.data[i].id;
}
if (!devices.includes(request.body.deviceId)) {
return response.send("Device ID does not exist."); //DOESN'T WORK
} else {
try {
const intervention_found = await tc_interventions.find_intervention(request.body.interventionId);
if (intervention_found < 1) {
return response.send("Intervention ID does not exist."); //DOESN'T WORK
} else {
number = await tc_device_intervention.find_device_intervention(request.body.deviceId, request.body.interventionId);
if(number < 1){
await tc_device_intervention.insert_device_intervention(request.body.deviceId, request.body.interventionId);
}
}
} catch (err) {
console.error(err);
}
}
if(number < 1){
return response.status(201).send(request.body); // WORKS
}else{
return response.send("Device-Intervention existing yet."); //WORKS
}
})();
return;
}
}
});