The code below is causing the following console error: Can not use keyword 'await' outside an async function.
async getData() {
// an await occurs here for something else
const menu = {
'pounds': 'DemandModification',
'combination': 'DemandCombinationOverride'
};
const overridesWithStaleBuckets = {};
Object.entries(menu).forEach(o => {
const overrideType = o[0];
const api = o[1];
const overrides = await this.$http.execute('read', api);
overridesWithStaleBuckets[overrideType] = overridesWithStaleBuckets[overrideType] || {};
overridesWithStaleBuckets[overrideType] = overrides;
});
// non problematic logic omitted
return overridesWithStaleBuckets;
}
The console specifically calls out the await
in this line as being the issue:
const overrides = await this.$http.execute('read', api);
Why is this error occurring when the function is async?