// ------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information. // ------------------------------------------------------------------------------ using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Text; namespace Microsoft.Graph { /// /// The error details object. /// Models OData protocol, 9.4 Error Response Body details object. /// http://docs.oasis-open.org/odata/odata/v4.01/csprd05/part1-protocol/odata-v4.01-csprd05-part1-protocol.html#_Toc14172757 /// [JsonObject(MemberSerialization = MemberSerialization.OptIn)] public class ErrorDetail { /// /// This code serves as a sub-status for the error code specified in the Error object. /// [JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName = "code", Required = Required.Default)] public string Code { get; set; } /// /// The error message. /// [JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName = "message", Required = Required.Default)] public string Message { get; set; } /// /// Indicates the target of the error, for example, the name of the property in error. /// [JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName = "target", Required = Required.Default)] public string Target { get; set; } /// /// The AdditionalData property bag. /// [JsonExtensionData(ReadData = true)] public IDictionary AdditionalData { get; set; } /// /// Concatenates the error detail into a string. /// /// A string representation of an ErrorDetail object. public override string ToString() { var errorDetailsStringBuilder = new StringBuilder(); if (!string.IsNullOrEmpty(this.Code)) { errorDetailsStringBuilder.Append(Environment.NewLine); errorDetailsStringBuilder.AppendFormat("\t\tCode: {0}", this.Code); errorDetailsStringBuilder.Append(Environment.NewLine); } if (!string.IsNullOrEmpty(this.Message)) { errorDetailsStringBuilder.AppendFormat("\t\tMessage: {0}", this.Message); errorDetailsStringBuilder.Append(Environment.NewLine); } if (!string.IsNullOrEmpty(this.Target)) { errorDetailsStringBuilder.AppendFormat("\t\tTarget: {0}", this.Target); errorDetailsStringBuilder.Append(Environment.NewLine); } if (this.AdditionalData != null && this.AdditionalData.GetEnumerator().MoveNext()) { errorDetailsStringBuilder.Append("\t\tAdditionalData:"); errorDetailsStringBuilder.Append(Environment.NewLine); foreach (var prop in this.AdditionalData) { errorDetailsStringBuilder.AppendFormat("\t{0} : {1}", prop.Key, prop.Value.ToString()); errorDetailsStringBuilder.Append(Environment.NewLine); } } return errorDetailsStringBuilder.ToString(); } } }