Пример #1
0
        internal static Error Create(IDictionary <string, object> dict, IJsonSerializerStrategy strategy)
        {
            var error = new Error();

            error.FillValues(dict);

            object causedBy;

            if (dict.TryGetValue("caused_by", out causedBy))
            {
                error.CausedBy = (CausedBy)strategy.DeserializeObject(causedBy, typeof(CausedBy));
            }

            object rootCause;

            if (!dict.TryGetValue("root_cause", out rootCause))
            {
                return(error);
            }

            var os = rootCause as object[];

            if (os == null)
            {
                return(error);
            }
            error.RootCause = os.Select(o => (RootCause)strategy.DeserializeObject(o, typeof(RootCause))).ToList();
            return(error);
        }
Пример #2
0
        internal static ShardFailure CreateShardFailure(IDictionary <string, object> dict, IJsonSerializerStrategy strategy)
        {
            var f = new ShardFailure();

            if (dict.TryGetValue("shard", out var shard))
            {
                f.Shard = Convert.ToInt32(shard);
            }
            if (dict.TryGetValue("index", out var index))
            {
                f.Index = Convert.ToString(index);
            }
            if (dict.TryGetValue("node", out var node))
            {
                f.Node = Convert.ToString(node);
            }
            if (dict.TryGetValue("status", out var status))
            {
                f.Status = Convert.ToString(status);
            }
            if (dict.TryGetValue("reason", out var reason))
            {
                var cause = (ErrorCause)strategy.DeserializeObject(reason, typeof(ErrorCause));
                f.Reason = cause;
            }
            return(f);
        }
Пример #3
0
        internal static ServerError Create(IDictionary <string, object> dict, IJsonSerializerStrategy strategy)
        {
            var statusCode = -1;

            if (dict.TryGetValue("status", out var status))
            {
                statusCode = Convert.ToInt32(status);
            }

            if (!dict.TryGetValue("error", out var error))
            {
                return(null);
            }
            Error err;

            if (error is string s)
            {
                err = new Error {
                    Reason = s
                };
            }
            else
            {
                err = (Error)strategy.DeserializeObject(error, typeof(Error));
            }

            return(new ServerError(err, statusCode));
        }
Пример #4
0
        internal static ServerError Create(IDictionary <string, object> dict, IJsonSerializerStrategy strategy)
        {
            object status, error;
            int    statusCode = -1;

            if (dict.TryGetValue("status", out status))
            {
                statusCode = Convert.ToInt32(status);
            }

            if (!dict.TryGetValue("error", out error))
            {
                return(null);
            }
            Error err;
            var   s = error as string;

            if (s != null)
            {
                err = new Error {
                    Reason = s
                };
            }
            else
            {
                err = (Error)strategy.DeserializeObject(error, typeof(Error));
            }

            return(new ServerError
            {
                Status = statusCode,
                Error = err
            });
        }
Пример #5
0
		internal static Error Create(IDictionary<string, object> dict, IJsonSerializerStrategy strategy)
		{
			var error = new Error();
			error.FillValues(dict);
			object rootCause;
			if (!dict.TryGetValue("root_cause", out rootCause)) return error;

			var os = rootCause as object[];
			if (os == null) return error;
			error.RootCause = os.Select(o => (RootCause)strategy.DeserializeObject(o, typeof(RootCause))).ToList();
			return error;
		}
Пример #6
0
        internal static ErrorCause CreateErrorCause(IDictionary <string, object> dict, IJsonSerializerStrategy strategy)
        {
            var causedBy = new ErrorCause();

            causedBy.FillValues(dict);
            if (dict.TryGetValue("caused_by", out var innerCausedBy))
            {
                causedBy.CausedBy = (ErrorCause)strategy.DeserializeObject(innerCausedBy, typeof(ErrorCause));
            }

            causedBy.Metadata = ErrorCauseMetadata.CreateCauseMetadata(dict, strategy);

            return(causedBy);
        }
Пример #7
0
        private static Error ReadRootCause(IDictionary <string, object> dict, IJsonSerializerStrategy strategy, Error error)
        {
            if (!dict.TryGetValue("root_cause", out var rootCause))
            {
                return(error);
            }

            if (!(rootCause is object[] os))
            {
                return(error);
            }
            error.RootCause = os.Select(o => (ErrorCause)strategy.DeserializeObject(o, typeof(ErrorCause))).ToList().AsReadOnly();
            return(error);
        }
Пример #8
0
		internal static ServerError Create(IDictionary<string, object> dict, IJsonSerializerStrategy strategy)
		{
			object status, error;
			int statusCode = -1;
			if (dict.TryGetValue("status", out status))
				statusCode = Convert.ToInt32(status);

			if (!dict.TryGetValue("error", out error)) return null;

			return new ServerError
			{
				Status = statusCode,
				Error = (Error)strategy.DeserializeObject(error, typeof(Error))
			};
		}
Пример #9
0
        internal static Error CreateError(IDictionary <string, object> dict, IJsonSerializerStrategy strategy)
        {
            var error = new Error();

            error.FillValues(dict);

            if (dict.TryGetValue("caused_by", out var causedBy))
            {
                error.CausedBy = (ErrorCause)strategy.DeserializeObject(causedBy, typeof(ErrorCause));
            }

            if (dict.TryGetValue("headers", out var headers))
            {
                var d = (IDictionary <string, string>)strategy.DeserializeObject(headers, typeof(IDictionary <string, string>));
                if (d != null)
                {
                    error.Headers = new ReadOnlyDictionary <string, string>(d);
                }
            }

            error.Metadata = ErrorCauseMetadata.CreateCauseMetadata(dict, strategy);

            return(ReadRootCause(dict, strategy, error));
        }
Пример #10
0
            private static IReadOnlyCollection <ShardFailure> GetShardFailures(object value, IJsonSerializerStrategy strategy)
            {
                if (!(value is object[] objects))
                {
                    return(DefaultFailedShards);
                }

                var values = new List <ShardFailure>();

                foreach (var v in objects)
                {
                    var cause = (ShardFailure)strategy.DeserializeObject(v, typeof(ShardFailure));
                    if (cause != null)
                    {
                        values.Add(cause);
                    }
                }
                return(new ReadOnlyCollection <ShardFailure>(values.ToArray()));
            }
Пример #11
0
        internal static CausedBy Create(IDictionary <string, object> dict, IJsonSerializerStrategy strategy)
        {
            var    causedBy = new CausedBy();
            object reason;

            if (dict.TryGetValue("reason", out reason))
            {
                causedBy.Reason = Convert.ToString(reason);
            }
            object type;

            if (dict.TryGetValue("type", out type))
            {
                causedBy.Type = Convert.ToString(type);
            }
            object innerCausedBy;

            if (dict.TryGetValue("caused_by", out innerCausedBy))
            {
                causedBy.InnerCausedBy = (CausedBy)strategy.DeserializeObject(innerCausedBy, typeof(CausedBy));
            }

            return(causedBy);
        }
Пример #12
0
		internal static CausedBy Create(IDictionary<string, object> dict, IJsonSerializerStrategy strategy)
		{
			var causedBy = new CausedBy();
			object reason;
			if (dict.TryGetValue("reason", out reason)) causedBy.Reason = Convert.ToString(reason);
			object type;
			if (dict.TryGetValue("type", out type)) causedBy.Type = Convert.ToString(type);
			object innerCausedBy;
			if (dict.TryGetValue("caused_by", out innerCausedBy))
				causedBy.InnerCausedBy = (CausedBy)strategy.DeserializeObject(innerCausedBy, typeof(CausedBy));

			return causedBy;
		}