winsoroaks
winsoroaks12mo ago

long shot: debugging twilio API errors but cannot see logs

hi all! this is a long shot, but i'll try my luck. im trying to debug why my outbound call is successful only once out of the 10 times i try. i've added some log statements around the function but they dont show up in my convex dashboard logs. does anyone know why? im aware that this is using a node sdk and have add the "use node" pragma. it succeeded once miraculously. i am interested in getting more logs before i reach out to twilio's support.
export const outbound = action({
handler: async (ctx) => {
try {
const username = process.env.TWILIO_SID!
console.log("🚀 ~ file: say.ts:19 ~ handler: ~ username:", username) // has logs here

const password = process.env.TWILIO_AUTH_TOKEN!
const client = new twilio.Twilio(username, password, {
logLevel: "debug",
})

// no more logs starting here
client.calls
.create(
{
url: "http://demo.twilio.com/docs/voice.xml",
to: process.env.TO_MY_PHONE!,
from: process.env.FROM_TWILIO_PHONE!,
},
function (err, call) {
if (err) {
console.log("🚀 ~ file: say.ts:32 ~ handler: ~ err:", err)
} else {
console.log("🚀 ~ file: say.ts:32 ~ handler: ~ call:", call?.sid)
}
}
)
.then((call) => {
console.log(call.sid)
})
.catch((err) => {
console.log("🚀 ~ file: say.ts:32 ~ handler: ~ err:", err)
})
} catch (e) {
console.error(e)
throw e
}
},
})
export const outbound = action({
handler: async (ctx) => {
try {
const username = process.env.TWILIO_SID!
console.log("🚀 ~ file: say.ts:19 ~ handler: ~ username:", username) // has logs here

const password = process.env.TWILIO_AUTH_TOKEN!
const client = new twilio.Twilio(username, password, {
logLevel: "debug",
})

// no more logs starting here
client.calls
.create(
{
url: "http://demo.twilio.com/docs/voice.xml",
to: process.env.TO_MY_PHONE!,
from: process.env.FROM_TWILIO_PHONE!,
},
function (err, call) {
if (err) {
console.log("🚀 ~ file: say.ts:32 ~ handler: ~ err:", err)
} else {
console.log("🚀 ~ file: say.ts:32 ~ handler: ~ call:", call?.sid)
}
}
)
.then((call) => {
console.log(call.sid)
})
.catch((err) => {
console.log("🚀 ~ file: say.ts:32 ~ handler: ~ err:", err)
})
} catch (e) {
console.error(e)
throw e
}
},
})
thanks!
3 Replies
jamwt
jamwt12mo ago
@winsoroaks hi. is there a reason you're both providing a callback and a .then().catch() promise-style handler?
Michal Srb
Michal Srb12mo ago
// no more logs starting here
There's a missing await on the next line. The dashboard logs should be showing a warning about an unwaited Promise. Try
await client.calls
.create(
await client.calls
.create(
etc. and see if it fixes the issue.
winsoroaks
winsoroaksOP12mo ago
oh thanks guys! adding await works 🙏 sorry for the noise 🤦‍♂️ yea! normally i'd see the warning when await is missing in the convex funcs for mutation / query, weird it didnt show up this time

Did you find this page helpful?