Altairis.Fakturoid.Client.FakturoidException.PopulateFromResponse C# (CSharp) Method

PopulateFromResponse() private method

Populates the exception properties from already set HttpResponseMessage in Response property.
private PopulateFromResponse ( ) : void
return void
        private void PopulateFromResponse()
        {
            // Publish response body
            this.ResponseBody = this.Response.Content.ReadAsStringAsync().Result;

            // Populate list of errors
            var errors = new List<KeyValuePair<string, string>>();
            if ((int)this.Response.StatusCode == 422) {
                // Unprocessable entity
                try {
                    // Try to deserialize the error structure
                    var jsonError = (JObject)JsonConvert.DeserializeObject(this.ResponseBody);
                    foreach (var prop in jsonError["errors"].Children().OfType<JProperty>()) {
                        var valueArray = ((JArray)prop.Value).Select(x => ((JValue)x).Value as string);
                        foreach (var value in valueArray) {
                            errors.Add(new KeyValuePair<string, string>(prop.Name, value));
                        }
                    }
                }
                catch (Exception ex) {
                    // Deserialization failed
                    errors.Add(new KeyValuePair<string, string>("json_parse_on_client_failed", "Error while parsing received body: " + ex.Message));
                }
            }
            this.Errors = errors;
        }