Better resilience against exceptions in view models in callViewModels

This commit is contained in:
Gina Häußge 2016-11-17 17:15:28 +01:00
parent 07382d3918
commit f1a1b851ee

View file

@ -832,17 +832,21 @@ function callViewModelsIf(allViewModels, method, condition, callback) {
_.each(allViewModels, function(viewModel) {
if (viewModel.hasOwnProperty(method) && condition(viewModel, method)) {
if (callback == undefined) {
if (parameters != undefined) {
// call the method with the provided parameters
viewModel[method].apply(viewModel, parameters);
try {
if (callback == undefined) {
if (parameters != undefined) {
// call the method with the provided parameters
viewModel[method].apply(viewModel, parameters);
} else {
// call the method without parameters
viewModel[method]();
}
} else {
// call the method without parameters
viewModel[method]();
// provide the method to the callback
callback(viewModel[method], viewModel);
}
} else {
// provide the method to the callback
callback(viewModel[method], viewModel);
} catch (exc) {
log.error("Error calling", method, "on view model", viewModel.constructor.name, ":", (exc.stack || exc));
}
}
});