Make Http hosting model able to report exceptions that happened while locating the function to invoke

This commit is contained in:
SteveSandersonMS
2016-07-06 15:47:06 +01:00
parent 7ce5f8d4ad
commit 4ee09cbe82
2 changed files with 15 additions and 15 deletions

View File

@@ -67,12 +67,6 @@
}
var server = http.createServer(function (req, res) {
readRequestBodyAsJson(req, function (bodyJson) {
var resolvedPath = path.resolve(process.cwd(), bodyJson.moduleName);
var invokedModule = dynamicRequire(resolvedPath);
var func = bodyJson.exportedFunctionName ? invokedModule[bodyJson.exportedFunctionName] : invokedModule;
if (!func) {
throw new Error('The module "' + resolvedPath + '" has no export named "' + bodyJson.exportedFunctionName + '"');
}
var hasSentResult = false;
var callback = function (errorValue, successValue) {
if (!hasSentResult) {
@@ -110,6 +104,12 @@
}
});
try {
var resolvedPath = path.resolve(process.cwd(), bodyJson.moduleName);
var invokedModule = dynamicRequire(resolvedPath);
var func = bodyJson.exportedFunctionName ? invokedModule[bodyJson.exportedFunctionName] : invokedModule;
if (!func) {
throw new Error('The module "' + resolvedPath + '" has no export named "' + bodyJson.exportedFunctionName + '"');
}
func.apply(null, [callback].concat(bodyJson.args));
}
catch (synchronousException) {