mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-22 17:47:53 +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) {
|
||||
|
||||
@@ -16,13 +16,6 @@ if (parsedArgs.watch) {
|
||||
|
||||
const server = http.createServer((req, res) => {
|
||||
readRequestBodyAsJson(req, bodyJson => {
|
||||
const resolvedPath = path.resolve(process.cwd(), bodyJson.moduleName);
|
||||
const invokedModule = dynamicRequire(resolvedPath);
|
||||
const func = bodyJson.exportedFunctionName ? invokedModule[bodyJson.exportedFunctionName] : invokedModule;
|
||||
if (!func) {
|
||||
throw new Error('The module "' + resolvedPath + '" has no export named "' + bodyJson.exportedFunctionName + '"');
|
||||
}
|
||||
|
||||
let hasSentResult = false;
|
||||
const callback = (errorValue, successValue) => {
|
||||
if (!hasSentResult) {
|
||||
@@ -31,9 +24,9 @@ const server = http.createServer((req, res) => {
|
||||
res.statusCode = 500;
|
||||
|
||||
if (errorValue.stack) {
|
||||
res.end(errorValue.stack);
|
||||
res.end(errorValue.stack);
|
||||
} else {
|
||||
res.end(errorValue.toString());
|
||||
res.end(errorValue.toString());
|
||||
}
|
||||
} else if (typeof successValue !== 'string') {
|
||||
// Arbitrary object/number/etc - JSON-serialize it
|
||||
@@ -61,6 +54,13 @@ const server = http.createServer((req, res) => {
|
||||
});
|
||||
|
||||
try {
|
||||
const resolvedPath = path.resolve(process.cwd(), bodyJson.moduleName);
|
||||
const invokedModule = dynamicRequire(resolvedPath);
|
||||
const 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) {
|
||||
callback(synchronousException, null);
|
||||
|
||||
Reference in New Issue
Block a user