Skip to content

Commit 80575a0

Browse files
Don't ignore synchronous errors when calling Node
1 parent 918d8d4 commit 80575a0

4 files changed

Lines changed: 31 additions & 19 deletions

File tree

Microsoft.AspNet.AngularServices/Content/Node/angular-rendering.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,21 @@ function findAngularComponent(options) {
3131

3232
module.exports = {
3333
renderToString: function(callback, options) {
34-
var component = findAngularComponent(options);
35-
var serverBindings = [
36-
ngRouter.ROUTER_BINDINGS,
37-
ngUniversal.HTTP_PROVIDERS,
38-
ng.provide(ngUniversal.BASE_URL, { useValue: options.requestUrl }),
39-
ngUniversal.SERVER_LOCATION_PROVIDERS
40-
];
34+
try {
35+
var component = findAngularComponent(options);
36+
var serverBindings = [
37+
ngRouter.ROUTER_BINDINGS,
38+
ngUniversal.HTTP_PROVIDERS,
39+
ng.provide(ngUniversal.BASE_URL, { useValue: options.requestUrl }),
40+
ngUniversal.SERVER_LOCATION_PROVIDERS
41+
];
4142

42-
return ngUniversal.renderToString(component, serverBindings).then(
43-
function(successValue) { callback(null, successValue); },
44-
function(errorValue) { callback(errorValue); }
45-
);
43+
return ngUniversal.renderToString(component, serverBindings).then(
44+
function(successValue) { callback(null, successValue); },
45+
function(errorValue) { callback(errorValue); }
46+
);
47+
} catch (synchronousException) {
48+
callback(synchronousException);
49+
}
4650
}
4751
};

Microsoft.AspNet.NodeServices/Content/Node/entrypoint-http.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ var server = http.createServer(function(req, res) {
3939
}
4040
};
4141

42-
func.apply(null, [callback].concat(bodyJson.args));
42+
try {
43+
func.apply(null, [callback].concat(bodyJson.args));
44+
} catch (synchronousException) {
45+
callback(synchronousException, null);
46+
}
4347
});
4448
});
4549

Microsoft.AspNet.NodeServices/HostingModels/HttpNodeInstance.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ public override async Task<T> Invoke<T>(NodeInvocationInfo invocationInfo) {
3232
var response = await client.PostAsync("http://localhost:" + this._portNumber, payload);
3333
var responseString = await response.Content.ReadAsStringAsync();
3434

35-
if (response.StatusCode != HttpStatusCode.OK) {
36-
throw new Exception("Node module responded with error: " + responseString);
35+
if (!response.IsSuccessStatusCode) {
36+
throw new Exception("Call to Node module failed with error: " + responseString);
3737
}
3838

3939
var responseIsJson = response.Content.Headers.ContentType.MediaType == "application/json";

Microsoft.AspNet.ReactServices/Content/Node/react-rendering.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,14 @@ function loadViaBabel(module, filename) {
4545

4646
module.exports = {
4747
renderToString: function(callback, options) {
48-
var component = findReactComponent(options);
49-
var history = createMemoryHistory(options.requestUrl);
50-
var reactElement = React.createElement(component, { history: history });
51-
var html = ReactDOMServer.renderToString(reactElement);
52-
callback(null, html);
48+
try {
49+
var component = findReactComponent(options);
50+
var history = createMemoryHistory(options.requestUrl);
51+
var reactElement = React.createElement(component, { history: history });
52+
var html = ReactDOMServer.renderToString(reactElement);
53+
callback(null, html);
54+
} catch (synchronousException) {
55+
callback(synchronousException);
56+
}
5357
}
5458
};

0 commit comments

Comments
 (0)