1 year ago
#384940
Ridhwaan Shakeel
AWS SES sendEmail(...).promise().then(...) TypeError: Cannot read property 'then' of undefined
using node v14.18.1
sesLib
is an import.const sesLib = new AWS.SESV2({ ...})
is defined elsewhere
From MDN documentation:
The then() method returns a Promise. It takes up to two arguments: callback functions for the success and failure cases of the Promise.
I am using the SendEmail feature in AWS SES V2 SDK using with .promise()
method to test for empty/null values in the To email address field
original code
const sendEmailImpl = (other_params, sesLib) => {
...
const params = { ... };
return sesLib.sendEmail(params).promise();
};
I tried the following code, all different variations but they result in the message - Cannot read property 'then' of undefined
const sendEmailImpl = (other_params, sesLib) => {
...
const params = { ... };
return sesLib.sendEmail(params).promise()
.then((data) => {
console.log(data)
resolve(data); // tried with & without resolve statement
})
.catch((err) => {
console.log('error', JSON.stringify(err));
reject(
'error', JSON.stringify(err); // tried with & without reject statement
);
throw new Exception(...);
});
};
const sendEmailImpl = async (other_params, sesLib) => {
...
const params = { ... };
var sendEmailPromise = await sesLib.sendEmail(params).promise();
sendEmailPromise.then((ok) => {
return ok;
})
.catch((err) => {
console.log('error', JSON.stringify(err));
reject(
'error', JSON.stringify(err); // tried with & without reject statement
);
throw new Exception(...);
});
};
After running npm test and jest
, it always returns the following error
TypeError: Cannot read property 'then' of undefined
...
sesLib.sendEmail(params).promise()
^
.then((data) => {
...
AWS Doc about promises
https://aws.amazon.com/blogs/developer/support-for-promises-in-the-sdk/
SES SendEmail API
https://docs.aws.amazon.com/ses/latest/APIReference/API_SendEmail.html
https://docs.aws.amazon.com/ses/latest/dg/send-email-concepts-email-format.html
javascript
node.js
amazon-web-services
promise
amazon-ses
0 Answers
Your Answer