var workqueue = [ autoFillRule.createNodes,
autoFillRuleGroup.createNodes,
fieldDefinition.createNodes,
fieldValidation.createNodes,
formDefinition.createNodes,
formDefinitionEmail.createNodes,
formDefinitionImage.createNodes,
formDefinitionImageIndex.createNodes,
pageDefinition.createNodes,
pageValidation.createNodes,
validationRule.createNodes,
workItem.createNodes
];
return Promise.all(workqueue.map(function(work) {
return work().then(function (result) {
return result;
}).catch(function (err) {
return err;
});
})).catch(function (err) {
return err;
});
Each of these functions (in the workqueue look like:
var request = new sql.Request();
var query = 'select r.autoFillRuleID, r.autoFillRuleGroupID, r.sourceFieldKey, r.destinationFieldKey, r.ordinal' +
' from [EForms].[OnlineForm].[AutoFillRule] r';
return request.query(query).then(function(rows) {
return Promise.all(rows.map(function(row) {
var props = {};
for (var property in row) {
if (row.hasOwnProperty(property)) {
props[property] = row[property];
}
}
props['id'] = row.autoFillRuleID;
var params = {
props: props
};
return new Promise(function(resolve, reject) {
db.query("CREATE (n:AutoFileRule {props}) RETURN n", params, function(err, result) {
if(err) {
reject(err);
} else {
resolve(result);
}
});
});
})).catch(function(err) {
return err;
});
}).catch(function(err) {
return err;
});
The problem is that errors are not being returned as errors. For example if I change one of the column names (this is a SQL query) so that the query fails then I would expect the SQL error to be caught in the "reject" portion of the promise. It is not (I would expect the error to show up in the 'catch'). Also (I am using Node-Neo4j) the statement beginning with 'db.query(' returns an error because the database is not started up yet. But the error is returned as part of the "result" and not the error. Ideas on how I should structure this so the error shows up in the right place?
Thank you.