Running into this error for the below code block. You can see that I instantiate report = []
inside of an async
function but before I run an async Promise.all
. Inside of that promise, I run some processing which should take data and push it back into the report
array which is scoped outside of the promise. I have tried changing to let
from const
as well as putting the Promise.all
into a try/catch
block but always get the same error...
Full Error:
TypeError: report.push(...) is not a function
(node:2568) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
Code:
(async (env) => {
const report = []
const subscriptions = await xm.subscriptions.getMany(env);
await Promise.all(subscriptions.map(sub => {
let apps_and_lobs = xm.subscriptions.process_apps_and_lobs(sub.criteria.data);
let sub_obj = {
sub_name : sub.name,
sub_uuid : sub.id,
form_name : sub.form.name,
form_id : sub.form.id,
plan_name : sub.form.plan.name,
plan_id : sub.form.plan.id,
owner_targetName : sub.owner.targetName,
owner_firstName : sub.owner.firstName,
owner_lastName : sub.owner.lastName,
applications : apps_and_lobs.apps,
lob : apps_and_lobs.lobs
}
report.push(sub_obj) // <----- ***** This is failing ******
(async (env) => {
let recipients = await xm.subscriptions.getSubscribers(env, null, sub.id);
recipients.map(r => {
util.cmt(JSON.stringify(r, null, 2));
})
})(env)
}))
})(prod);