Example #1
0
        internal DocumentTranslationError(DocumentTranslationErrorCode errorCode, string message)
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            ErrorCode = errorCode;
            Message   = message;
        }
 internal DocumentTranslationError(DocumentTranslationErrorCode errorCode, string message, string target, InnerErrorV2 innerError)
 {
     if (innerError != null)
     {
         // Assigns the inner error, which should be only one level down.
         ErrorCode = innerError.Code;
         Message   = innerError.Message;
         Target    = innerError.Target;
     }
     else
     {
         ErrorCode = errorCode;
         Message   = message;
         Target    = target;
     }
 }
Example #3
0
        internal static DocumentTranslationError DeserializeDocumentTranslationError(JsonElement element)
        {
            Optional <DocumentTranslationErrorCode> code = default;
            string                  message    = default;
            Optional <string>       target     = default;
            Optional <InnerErrorV2> innerError = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("code"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    code = new DocumentTranslationErrorCode(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("message"))
                {
                    message = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("target"))
                {
                    target = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("innerError"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    innerError = InnerErrorV2.DeserializeInnerErrorV2(property.Value);
                    continue;
                }
            }
            return(new DocumentTranslationError(Optional.ToNullable(code), message, target.Value, innerError.Value));
        }