mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-23 10:08:57 +00:00
Make Http hosting model able to report exceptions that happened while locating the function to invoke
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user