Tengo este fragmento de código. En algún punto de este código, puedo obtener response.send
... en otros puntos, obtengo el error response.send is not a function
. A continuación destaco en qué puntos sucede esto:
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; } } });