mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-23 01:58:29 +00:00
Don't ignore synchronous errors when calling Node
This commit is contained in:
@@ -31,17 +31,21 @@ function findAngularComponent(options) {
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
renderToString: function(callback, options) {
|
renderToString: function(callback, options) {
|
||||||
var component = findAngularComponent(options);
|
try {
|
||||||
var serverBindings = [
|
var component = findAngularComponent(options);
|
||||||
ngRouter.ROUTER_BINDINGS,
|
var serverBindings = [
|
||||||
ngUniversal.HTTP_PROVIDERS,
|
ngRouter.ROUTER_BINDINGS,
|
||||||
ng.provide(ngUniversal.BASE_URL, { useValue: options.requestUrl }),
|
ngUniversal.HTTP_PROVIDERS,
|
||||||
ngUniversal.SERVER_LOCATION_PROVIDERS
|
ng.provide(ngUniversal.BASE_URL, { useValue: options.requestUrl }),
|
||||||
];
|
ngUniversal.SERVER_LOCATION_PROVIDERS
|
||||||
|
];
|
||||||
|
|
||||||
return ngUniversal.renderToString(component, serverBindings).then(
|
return ngUniversal.renderToString(component, serverBindings).then(
|
||||||
function(successValue) { callback(null, successValue); },
|
function(successValue) { callback(null, successValue); },
|
||||||
function(errorValue) { callback(errorValue); }
|
function(errorValue) { callback(errorValue); }
|
||||||
);
|
);
|
||||||
|
} catch (synchronousException) {
|
||||||
|
callback(synchronousException);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -32,8 +32,8 @@ namespace Microsoft.AspNet.NodeServices {
|
|||||||
var response = await client.PostAsync("http://localhost:" + this._portNumber, payload);
|
var response = await client.PostAsync("http://localhost:" + this._portNumber, payload);
|
||||||
var responseString = await response.Content.ReadAsStringAsync();
|
var responseString = await response.Content.ReadAsStringAsync();
|
||||||
|
|
||||||
if (response.StatusCode != HttpStatusCode.OK) {
|
if (!response.IsSuccessStatusCode) {
|
||||||
throw new Exception("Node module responded with error: " + responseString);
|
throw new Exception("Call to Node module failed with error: " + responseString);
|
||||||
}
|
}
|
||||||
|
|
||||||
var responseIsJson = response.Content.Headers.ContentType.MediaType == "application/json";
|
var responseIsJson = response.Content.Headers.ContentType.MediaType == "application/json";
|
||||||
|
|||||||
@@ -45,10 +45,14 @@ function loadViaBabel(module, filename) {
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
renderToString: function(callback, options) {
|
renderToString: function(callback, options) {
|
||||||
var component = findReactComponent(options);
|
try {
|
||||||
var history = createMemoryHistory(options.requestUrl);
|
var component = findReactComponent(options);
|
||||||
var reactElement = React.createElement(component, { history: history });
|
var history = createMemoryHistory(options.requestUrl);
|
||||||
var html = ReactDOMServer.renderToString(reactElement);
|
var reactElement = React.createElement(component, { history: history });
|
||||||
callback(null, html);
|
var html = ReactDOMServer.renderToString(reactElement);
|
||||||
|
callback(null, html);
|
||||||
|
} catch (synchronousException) {
|
||||||
|
callback(synchronousException);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user