Don't ignore synchronous errors when calling Node

This commit is contained in:
SteveSandersonMS
2015-12-14 13:16:39 +00:00
parent 918d8d422a
commit 80575a092e
4 changed files with 31 additions and 19 deletions

View File

@@ -31,17 +31,21 @@ function findAngularComponent(options) {
module.exports = {
renderToString: function(callback, options) {
var component = findAngularComponent(options);
var serverBindings = [
ngRouter.ROUTER_BINDINGS,
ngUniversal.HTTP_PROVIDERS,
ng.provide(ngUniversal.BASE_URL, { useValue: options.requestUrl }),
ngUniversal.SERVER_LOCATION_PROVIDERS
];
try {
var component = findAngularComponent(options);
var serverBindings = [
ngRouter.ROUTER_BINDINGS,
ngUniversal.HTTP_PROVIDERS,
ng.provide(ngUniversal.BASE_URL, { useValue: options.requestUrl }),
ngUniversal.SERVER_LOCATION_PROVIDERS
];
return ngUniversal.renderToString(component, serverBindings).then(
function(successValue) { callback(null, successValue); },
function(errorValue) { callback(errorValue); }
);
return ngUniversal.renderToString(component, serverBindings).then(
function(successValue) { callback(null, successValue); },
function(errorValue) { callback(errorValue); }
);
} catch (synchronousException) {
callback(synchronousException);
}
}
};

View File

@@ -39,7 +39,11 @@ var server = http.createServer(function(req, res) {
}
};
func.apply(null, [callback].concat(bodyJson.args));
try {
func.apply(null, [callback].concat(bodyJson.args));
} catch (synchronousException) {
callback(synchronousException, null);
}
});
});

View File

@@ -32,8 +32,8 @@ namespace Microsoft.AspNet.NodeServices {
var response = await client.PostAsync("http://localhost:" + this._portNumber, payload);
var responseString = await response.Content.ReadAsStringAsync();
if (response.StatusCode != HttpStatusCode.OK) {
throw new Exception("Node module responded with error: " + responseString);
if (!response.IsSuccessStatusCode) {
throw new Exception("Call to Node module failed with error: " + responseString);
}
var responseIsJson = response.Content.Headers.ContentType.MediaType == "application/json";

View File

@@ -45,10 +45,14 @@ function loadViaBabel(module, filename) {
module.exports = {
renderToString: function(callback, options) {
var component = findReactComponent(options);
var history = createMemoryHistory(options.requestUrl);
var reactElement = React.createElement(component, { history: history });
var html = ReactDOMServer.renderToString(reactElement);
callback(null, html);
try {
var component = findReactComponent(options);
var history = createMemoryHistory(options.requestUrl);
var reactElement = React.createElement(component, { history: history });
var html = ReactDOMServer.renderToString(reactElement);
callback(null, html);
} catch (synchronousException) {
callback(synchronousException);
}
}
};