context.getTwilioClient() error
deshartman opened this issue · comments
I have hit an issue with context.getTwilioClient(). I have used it in the past, but now I get the below error from the simple code below. Can someone please help me out here to narrow down the issue. I have included my package.json file for ref.
exports.handler = async (context, event, callback) => {
const restClient = context.getTwilioClient();
return callback(null, { hello: 'world' });
}
This is the error when running this. (I'm using ngrok locally)
/Users/dhartman/Development/01_Twilio/twilio-stack/twilio-stack-server/node_modules/@twilio/runtime-handler/dist/dev-runtime/checks/check-auth-token.js:30
(_a = options.logger) === null || _a === void 0 ? void 0 : _a.error(message, title);
^
TypeError: _a.error is not a function
at Object.checkForValidAuthToken (/Users/dhartman/Development/01_Twilio/twilio-stack/twilio-stack-server/node_modules/@twilio/runtime-handler/dist/dev-runtime/checks/check-auth-token.js:30:71)
at Object.getTwilioClient (/Users/dhartman/Development/01_Twilio/twilio-stack/twilio-stack-server/node_modules/@twilio/runtime-handler/dist/dev-runtime/route.js:124:28)
at exports.handler (/Users/dhartman/Development/01_Twilio/twilio-stack/twilio-stack-server/functions/getJSONData.js:16:32)
at process.<anonymous> (/Users/dhartman/Development/01_Twilio/twilio-stack/twilio-stack-server/node_modules/@twilio/runtime-handler/dist/dev-runtime/internal/functionRunner.js:74:9)
at process.emit (node:events:527:28)
at emit (node:internal/child_process:938:14)
at processTicksAndRejections (node:internal/process/task_queues:84:21)
My package.json file
"name": "twilio-stack-server",
"version": "0.0.0",
"private": true,
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "twilio-run",
"deploy": "twilio-run deploy"
},
"dependencies": {
"@twilio/runtime-handler": "1.3.0",
"twilio": "^3.56"
},
"devDependencies": {
"twilio-run": "^3.5.2"
},
"engines": {
"node": "16"
}
}```
Here is a simple gitHub example
Hi Des!
So the error is indeed odd. It looks like the logger
instance is not appropriately passed through. I have to investigate a bit more. What's happening is that you are trying to create a client
but your .env
file doesn't contain an AUTH_TOKEN
so the check is trying to throw an error to let you know but it's failing because it can't access the logger method correctly.
I'll dig more into why that's happening in the coming days. Thanks for filing this
Bugger!
Can't believe I missed that. I went and check older projects where this works and they have the AUTH_TOKEN. Thanks for the point out.
I guess the error does point this out in hindsight.