internal static ApiError DeserializeApiError(JsonElement element)
        {
            Optional <IReadOnlyList <ApiErrorBase> > details = default;
            Optional <InnerError> innererror = default;
            Optional <string>     code       = default;
            Optional <string>     target     = default;
            Optional <string>     message    = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("details"))
                {
                    List <ApiErrorBase> array = new List <ApiErrorBase>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(ApiErrorBase.DeserializeApiErrorBase(item));
                    }
                    details = array;
                    continue;
                }
                if (property.NameEquals("innererror"))
                {
                    innererror = InnerError.DeserializeInnerError(property.Value);
                    continue;
                }
                if (property.NameEquals("code"))
                {
                    code = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("target"))
                {
                    target = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("message"))
                {
                    message = property.Value.GetString();
                    continue;
                }
            }
            return(new ApiError(Optional.ToList(details), innererror.Value, code.Value, target.Value, message.Value));
        }
예제 #2
0
        internal static ApiError DeserializeApiError(JsonElement element)
        {
            IList <ApiErrorBase> details    = default;
            InnerError           innererror = default;
            string code    = default;
            string target  = default;
            string message = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("details"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    List <ApiErrorBase> array = new List <ApiErrorBase>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        if (item.ValueKind == JsonValueKind.Null)
                        {
                            array.Add(null);
                        }
                        else
                        {
                            array.Add(ApiErrorBase.DeserializeApiErrorBase(item));
                        }
                    }
                    details = array;
                    continue;
                }
                if (property.NameEquals("innererror"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    innererror = InnerError.DeserializeInnerError(property.Value);
                    continue;
                }
                if (property.NameEquals("code"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    code = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("target"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    target = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("message"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    message = property.Value.GetString();
                    continue;
                }
            }
            return(new ApiError(details, innererror, code, target, message));
        }