Exemple #1
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);
        }
Exemple #2
0
        public override object DeserializeObject(object value, Type type)
        {
            if (type == typeof(DynamicBody))
            {
                var dict = base.DeserializeObject(value, typeof(IDictionary <string, object>)) as IDictionary <string, object>;
                return(dict == null ? null : DynamicBody.Create(dict));
            }
            if (type == typeof(ServerError))
            {
                var dict = base.DeserializeObject(value, typeof(IDictionary <string, object>)) as IDictionary <string, object>;
                return(ServerError.Create(dict, this));
            }
            if (type == typeof(ShardFailure))
            {
                var dict = base.DeserializeObject(value, typeof(IDictionary <string, object>)) as IDictionary <string, object>;
                return(ShardFailure.CreateShardFailure(dict, this));
            }
            if (type == typeof(Error))
            {
                if (value is string s)
                {
                    return new Error {
                               Reason = s
                    }
                }
                ;

                var dict = base.DeserializeObject(value, typeof(IDictionary <string, object>)) as IDictionary <string, object>;
                return(Error.CreateError(dict, this));
            }
            if (type == typeof(ErrorCause))
            {
                if (value is string s)
                {
                    return new ErrorCause {
                               Reason = s
                    }
                }
                ;

                var dict = base.DeserializeObject(value, typeof(IDictionary <string, object>)) as IDictionary <string, object>;
                return(ErrorCause.CreateErrorCause(dict, this));
            }
            return(base.DeserializeObject(value, type));
        }
    }
}
        public static void FillValues(this ErrorCause rootCause, IDictionary <string, object> dict)
        {
            if (dict == null)
            {
                return;
            }
            if (dict.TryGetValue("reason", out var reason))
            {
                rootCause.Reason = Convert.ToString(reason);
            }
            if (dict.TryGetValue("type", out var type))
            {
                rootCause.Type = Convert.ToString(type);
            }
            if (dict.TryGetValue("stack_trace", out var stackTrace))
            {
                rootCause.StackTrace = Convert.ToString(stackTrace);
            }

//			if (dict.TryGetValue("index", out var index)) rootCause.Index = Convert.ToString(index);
//			if (dict.TryGetValue("resource.id", out var resourceId)) rootCause.ResourceId = Convert.ToString(resourceId);
//			if (dict.TryGetValue("resource.type", out var resourceType)) rootCause.ResourceType = Convert.ToString(resourceType);
        }