Add handling of error response from node process

This commit is contained in:
Greg Beaty
2015-12-09 16:40:04 -05:00
parent 1e446b6797
commit f6bb28a71d

View File

@@ -29,6 +29,11 @@ namespace Microsoft.AspNet.NodeServices {
var payload = new StringContent(payloadJson, Encoding.UTF8, "application/json"); var payload = new StringContent(payloadJson, Encoding.UTF8, "application/json");
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) {
throw new Exception("Node module responded with error: " + responseString);
}
var responseIsJson = response.Content.Headers.ContentType.MediaType == "application/json"; var responseIsJson = response.Content.Headers.ContentType.MediaType == "application/json";
if (responseIsJson) { if (responseIsJson) {
return JsonConvert.DeserializeObject<T>(responseString); return JsonConvert.DeserializeObject<T>(responseString);