// ------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information. // ------------------------------------------------------------------------------ namespace Microsoft.Graph { using System; using System.Collections.Generic; using System.Text; using Newtonsoft.Json; /// /// The error object contained in 400 and 500 responses returned from the service. /// Models OData protocol, 9.4 Error Response Body /// 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 Error { /// /// This code represents the HTTP status code when this Error object accessed from the ServiceException.Error object. /// This code represent a sub-code when the Error object is in the InnerError or ErrorDetails 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; } /// /// An array of details that describe the error[s] encountered with the request. /// [JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName = "details", Required = Required.Default)] public IEnumerable Details { get; set; } /// /// The inner error of the response. These are additional error objects that may be more specific than the top level error. /// [JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName = "innererror", Required = Required.Default)] public Error InnerError { get; set; } /// /// The Throw site of the error. /// public string ThrowSite { get; internal set; } /// /// Gets or set the client-request-id header returned in the response headers collection. /// public string ClientRequestId { get; internal set; } /// /// The AdditionalData property bag. /// [JsonExtensionData(ReadData = true)] public IDictionary AdditionalData { get; set; } /// /// Concatenates the error into a string. /// /// A human-readable string error response. public override string ToString() { var errorStringBuilder = new StringBuilder(); if (!string.IsNullOrEmpty(this.Code)) { errorStringBuilder.AppendFormat("Code: {0}", this.Code); errorStringBuilder.Append(Environment.NewLine); } if (!string.IsNullOrEmpty(this.Message)) { errorStringBuilder.AppendFormat("Message: {0}", this.Message); errorStringBuilder.Append(Environment.NewLine); } if (!string.IsNullOrEmpty(this.Target)) { errorStringBuilder.AppendFormat("Target: {0}", this.Target); errorStringBuilder.Append(Environment.NewLine); } if (this.Details != null && this.Details.GetEnumerator().MoveNext()) { errorStringBuilder.Append("Details:"); errorStringBuilder.Append(Environment.NewLine); int i = 0; foreach (var detail in this.Details) { errorStringBuilder.AppendFormat("\tDetail{0}:{1}", i, detail.ToString()); errorStringBuilder.Append(Environment.NewLine); i++; } } if (this.InnerError != null) { errorStringBuilder.Append("Inner error:"); errorStringBuilder.Append(Environment.NewLine); errorStringBuilder.Append("\t" + this.InnerError.ToString()); } if (!string.IsNullOrEmpty(this.ThrowSite)) { errorStringBuilder.AppendFormat("Throw site: {0}", this.ThrowSite); errorStringBuilder.Append(Environment.NewLine); } if (!string.IsNullOrEmpty(this.ClientRequestId)) { errorStringBuilder.AppendFormat("ClientRequestId: {0}", this.ClientRequestId); errorStringBuilder.Append(Environment.NewLine); } if (this.AdditionalData != null && this.AdditionalData.GetEnumerator().MoveNext()) { errorStringBuilder.Append("AdditionalData:"); errorStringBuilder.Append(Environment.NewLine); foreach (var prop in this.AdditionalData) { errorStringBuilder.AppendFormat("\t{0}: {1}", prop.Key, prop.Value.ToString()); errorStringBuilder.Append(Environment.NewLine); } } return errorStringBuilder.ToString(); } } }