fix(core): errors get swallowed if thrown inside async event functions (#10030)

This commit is contained in:
Dimitris-Rafail Katsampas
2022-09-28 02:57:11 +03:00
committed by GitHub
parent e3255c00d8
commit bdade0f0d5

View File

@ -294,10 +294,19 @@ export class Observable implements ObservableDefinition {
if (entry.once) {
observers.splice(i, 1);
}
let returnValue;
if (entry.thisArg) {
entry.callback.apply(entry.thisArg, [data]);
returnValue = entry.callback.apply(entry.thisArg, [data]);
} else {
entry.callback(data);
returnValue = entry.callback(data);
}
// This ensures errors thrown inside asynchronous functions do not get swallowed
if (returnValue && returnValue instanceof Promise) {
returnValue.catch((err) => {
console.error(err);
});
}
}
}