diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/src/AnalyzeSentimentResult.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/src/AnalyzeSentimentResult.cs index 2d51f1633f140..ba7d1b1859772 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/src/AnalyzeSentimentResult.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/src/AnalyzeSentimentResult.cs @@ -32,7 +32,7 @@ public DocumentSentiment DocumentSentiment if (HasError) { #pragma warning disable CA1065 // Do not raise exceptions in unexpected locations - throw new InvalidOperationException($"Cannot access result for document {Id}, due to error {Error.Code}: {Error.Message}"); + throw new InvalidOperationException($"Cannot access result for document {Id}, due to error {Error.ErrorCode}: {Error.Message}"); #pragma warning restore CA1065 // Do not raise exceptions in unexpected locations } return _documentSentiment; diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/src/DetectLanguageResult.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/src/DetectLanguageResult.cs index 9b766edbd4b93..7fd78201a8577 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/src/DetectLanguageResult.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/src/DetectLanguageResult.cs @@ -31,7 +31,7 @@ public DetectedLanguage PrimaryLanguage if (HasError) { #pragma warning disable CA1065 // Do not raise exceptions in unexpected locations - throw new InvalidOperationException($"Cannot access result for document {Id}, due to error {Error.Code}: {Error.Message}"); + throw new InvalidOperationException($"Cannot access result for document {Id}, due to error {Error.ErrorCode}: {Error.Message}"); #pragma warning restore CA1065 // Do not raise exceptions in unexpected locations } return _primaryLanguage; diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/src/ExtractKeyPhrasesResult.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/src/ExtractKeyPhrasesResult.cs index 54d08c1af49e3..ba61d749dbb8e 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/src/ExtractKeyPhrasesResult.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/src/ExtractKeyPhrasesResult.cs @@ -30,7 +30,7 @@ public KeyPhraseCollection KeyPhrases if (HasError) { #pragma warning disable CA1065 // Do not raise exceptions in unexpected locations - throw new InvalidOperationException($"Cannot access result for document {Id}, due to error {Error.Code}: {Error.Message}"); + throw new InvalidOperationException($"Cannot access result for document {Id}, due to error {Error.ErrorCode}: {Error.Message}"); #pragma warning restore CA1065 // Do not raise exceptions in unexpected locations } return _keyPhrases; diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/src/RecognizeEntitiesResult.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/src/RecognizeEntitiesResult.cs index 1da61414e7df8..0e1e4959bee21 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/src/RecognizeEntitiesResult.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/src/RecognizeEntitiesResult.cs @@ -32,7 +32,7 @@ public CategorizedEntityCollection Entities if (HasError) { #pragma warning disable CA1065 // Do not raise exceptions in unexpected locations - throw new InvalidOperationException($"Cannot access result for document {Id}, due to error {Error.Code}: {Error.Message}"); + throw new InvalidOperationException($"Cannot access result for document {Id}, due to error {Error.ErrorCode}: {Error.Message}"); #pragma warning restore CA1065 // Do not raise exceptions in unexpected locations } return _entities; diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/src/RecognizeLinkedEntitiesResult.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/src/RecognizeLinkedEntitiesResult.cs index ce69be00d4f01..e7fad82650563 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/src/RecognizeLinkedEntitiesResult.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/src/RecognizeLinkedEntitiesResult.cs @@ -32,7 +32,7 @@ public LinkedEntityCollection Entities if (HasError) { #pragma warning disable CA1065 // Do not raise exceptions in unexpected locations - throw new InvalidOperationException($"Cannot access result for document {Id}, due to error {Error.Code}: {Error.Message}"); + throw new InvalidOperationException($"Cannot access result for document {Id}, due to error {Error.ErrorCode}: {Error.Message}"); #pragma warning restore CA1065 // Do not raise exceptions in unexpected locations } return _linkedEntities; diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsClient.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsClient.cs index 4d040fbbb20a8..95013c369fe68 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsClient.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsClient.cs @@ -151,7 +151,7 @@ public virtual async Task> DetectLanguageAsync(string { // only one document, so we can ignore the id and grab the first error message. TextAnalyticsError error = result[0].Error; - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(response, error.Message, error.Code, CreateAdditionalInformation(error)).ConfigureAwait(false); + throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(response, error.Message, error.ErrorCode.ToString(), CreateAdditionalInformation(error)).ConfigureAwait(false); } return Response.FromValue(result[0].PrimaryLanguage, response); default: @@ -210,7 +210,7 @@ public virtual Response DetectLanguage(string document, string { // only one document, so we can ignore the id and grab the first error message. TextAnalyticsError error = result[0].Error; - throw _clientDiagnostics.CreateRequestFailedException(response, error.Message, error.Code, CreateAdditionalInformation(error)); + throw _clientDiagnostics.CreateRequestFailedException(response, error.Message, error.ErrorCode.ToString(), CreateAdditionalInformation(error)); } return Response.FromValue(result[0].PrimaryLanguage, response); default: @@ -439,7 +439,7 @@ public virtual async Task> RecognizeEntiti { // only one document, so we can ignore the id and grab the first error message. TextAnalyticsError error = results[0].Error; - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(response, error.Message, error.Code, CreateAdditionalInformation(error)).ConfigureAwait(false); + throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(response, error.Message, error.ErrorCode.ToString(), CreateAdditionalInformation(error)).ConfigureAwait(false); } return Response.FromValue((CategorizedEntityCollection)results[0].Entities, response); default: @@ -500,7 +500,7 @@ public virtual Response RecognizeEntities(string do { // only one document, so we can ignore the id and grab the first error message. TextAnalyticsError error = results[0].Error; - throw _clientDiagnostics.CreateRequestFailedException(response, error.Message, error.Code, CreateAdditionalInformation(error)); + throw _clientDiagnostics.CreateRequestFailedException(response, error.Message, error.ErrorCode.ToString(), CreateAdditionalInformation(error)); } return Response.FromValue((CategorizedEntityCollection)results[0].Entities, response); default: @@ -736,7 +736,7 @@ public virtual async Task> AnalyzeSentimentAsync(str { // only one document, so we can ignore the id and grab the first error message. TextAnalyticsError error = results[0].Error; - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(response, error.Message, error.Code, CreateAdditionalInformation(error)).ConfigureAwait(false); + throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(response, error.Message, error.ErrorCode.ToString(), CreateAdditionalInformation(error)).ConfigureAwait(false); } return Response.FromValue(results[0].DocumentSentiment, response); default: @@ -794,7 +794,7 @@ public virtual Response AnalyzeSentiment(string document, str { // only one document, so we can ignore the id and grab the first error message. TextAnalyticsError error = results[0].Error; - throw _clientDiagnostics.CreateRequestFailedException(response, error.Message, error.Code, CreateAdditionalInformation(error)); + throw _clientDiagnostics.CreateRequestFailedException(response, error.Message, error.ErrorCode.ToString(), CreateAdditionalInformation(error)); } return Response.FromValue(results[0].DocumentSentiment, response); default: @@ -1020,7 +1020,7 @@ public virtual async Task> ExtractKeyPhrasesAsync( { // only one document, so we can ignore the id and grab the first error message. TextAnalyticsError error = results[0].Error; - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(response, error.Message, error.Code, CreateAdditionalInformation(error)).ConfigureAwait(false); + throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(response, error.Message, error.ErrorCode.ToString(), CreateAdditionalInformation(error)).ConfigureAwait(false); } return Response.FromValue((KeyPhraseCollection) results[0].KeyPhrases, response); default: @@ -1080,7 +1080,7 @@ public virtual Response ExtractKeyPhrases(string document, { // only one document, so we can ignore the id and grab the first error message. TextAnalyticsError error = results[0].Error; - throw _clientDiagnostics.CreateRequestFailedException(response, error.Message, error.Code, CreateAdditionalInformation(error)); + throw _clientDiagnostics.CreateRequestFailedException(response, error.Message, error.ErrorCode.ToString(), CreateAdditionalInformation(error)); } return Response.FromValue((KeyPhraseCollection)results[0].KeyPhrases, response); default: @@ -1313,7 +1313,7 @@ public virtual async Task> RecognizeLinkedEntit { // only one document, so we can ignore the id and grab the first error message. TextAnalyticsError error = results[0].Error; - throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(response, error.Message, error.Code, CreateAdditionalInformation(error)).ConfigureAwait(false); + throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(response, error.Message, error.ErrorCode.ToString(), CreateAdditionalInformation(error)).ConfigureAwait(false); } return Response.FromValue((LinkedEntityCollection)results[0].Entities, response); default: @@ -1372,7 +1372,7 @@ public virtual Response RecognizeLinkedEntities(string d { // only one document, so we can ignore the id and grab the first error message. TextAnalyticsError error = results[0].Error; - throw _clientDiagnostics.CreateRequestFailedException(response, error.Message, error.Code, CreateAdditionalInformation(error)); + throw _clientDiagnostics.CreateRequestFailedException(response, error.Message, error.ErrorCode.ToString(), CreateAdditionalInformation(error)); } return Response.FromValue((LinkedEntityCollection)results[0].Entities, response); default: diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsError.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsError.cs index 995476693674d..5265188f92338 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsError.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsError.cs @@ -10,7 +10,7 @@ public struct TextAnalyticsError { internal TextAnalyticsError(string code, string message, string target = null) { - Code = code; + ErrorCode = code; Message = message; Target = target; } @@ -18,7 +18,7 @@ internal TextAnalyticsError(string code, string message, string target = null) /// /// Error code that serves as an indicator of the HTTP error code. /// - public string Code { get; } + public TextAnalyticsErrorCode ErrorCode { get; } /// /// Message that contains more information about the reason of the error. diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsErrorCode.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsErrorCode.cs new file mode 100644 index 0000000000000..e66435a33f313 --- /dev/null +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsErrorCode.cs @@ -0,0 +1,146 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.ComponentModel; +using Azure.Core; + +namespace Azure.AI.TextAnalytics +{ + /// + /// Text Analytics error code values. + /// + public readonly struct TextAnalyticsErrorCode : IEquatable + { + private readonly string _value; + + /// + /// Specifies that the error code is an invalid request. + /// + public static readonly string InvalidRequest = "invalidRequest"; + + /// + /// Specifies that the error code is an invalid argument. + /// + public static readonly string InvalidArgument = "invalidArgument"; + + /// + /// Specifies that the error code is an internal server error. + /// + public static readonly string InternalServerError = "internalServerError"; + + /// + /// Specifies that the error code is service unavailable. + /// + public static readonly string ServiceUnavailable = "serviceUnavailable"; + + /// + /// Specifies that the error code is an invalid parameter value. + /// + public static readonly string InvalidParameterValue = "invalidParameterValue"; + + /// + /// Specifies that the error code is an invalid request body format. + /// + public static readonly string InvalidRequestBodyFormat = "invalidRequestBodyFormat"; + + /// + /// Specifies that the error code is an empty request. + /// + public static readonly string EmptyRequest = "emptyRequest"; + + /// + /// Specifies that the error code is a missing input records. + /// + public static readonly string MissingInputRecords = "missingInputRecords"; + + /// + /// Specifies that the error code is an invalid document. + /// + public static readonly string InvalidDocument = "invalidDocument"; + + /// + /// Specifies that the error code is model version incorrect. + /// + public static readonly string ModelVersionIncorrect = "modelVersionIncorrect"; + + /// + /// Specifies that the error code is an invalid document batch. + /// + public static readonly string InvalidDocumentBatch = "invalidDocumentBatch"; + + /// + /// Specifies that the error code is an unsupported language code. + /// + public static readonly string UnsupportedLanguageCode = "unsupportedLanguageCode"; + + /// + /// Specifies that the error code is an invalid country hint. + /// + public static readonly string InvalidCountryHint = "invalidCountryHint"; + + private TextAnalyticsErrorCode(string errorCode) + { + Argument.AssertNotNullOrEmpty(errorCode, nameof(errorCode)); + _value = errorCode; + } + + /// + /// Defines implicit conversion from string to TextAnalyticsErrorCode. + /// + /// string to convert. + /// The string as an TextAnalyticsErrorCode. + public static implicit operator TextAnalyticsErrorCode(string errorCode) => new TextAnalyticsErrorCode(errorCode); + + /// + /// Defines explicit conversion from TextAnalyticsErrorCode to string. + /// + /// TextAnalyticsErrorCode to convert. + /// The TextAnalyticsErrorCode as a string. + public static explicit operator string(TextAnalyticsErrorCode errorCode) => errorCode._value; + + /// + /// Compares two TextAnalyticsErrorCode values for equality. + /// + /// The first TextAnalyticsErrorCode to compare. + /// The second TextAnalyticsErrorCode to compare. + /// true if the TextAnalyticsErrorCode objects are equal or are both null; false otherwise. + public static bool operator ==(TextAnalyticsErrorCode left, TextAnalyticsErrorCode right) => Equals(left, right); + + /// + /// Compares two TextAnalyticsErrorCode values for inequality. + /// + /// The first TextAnalyticsErrorCode to compare. + /// The second TextAnalyticsErrorCode to compare. + /// true if the TextAnalyticsErrorCode objects are not equal; false otherwise. + public static bool operator !=(TextAnalyticsErrorCode left, TextAnalyticsErrorCode right) => !Equals(left, right); + + /// + /// Compares the TextAnalyticsErrorCode for equality with another TextAnalyticsErrorCode. + /// + /// The TextAnalyticsErrorCode with which to compare. + /// true if the TextAnalyticsErrorCode objects are equal; otherwise, false. + public bool Equals(TextAnalyticsErrorCode other) => _value == other._value; + + /// + /// Determines whether the specified object is equal to the current object. + /// + /// The object to compare with the current object. + /// true if the specified object is equal to the current object; otherwise, false. + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is TextAnalyticsErrorCode errorCode && Equals(errorCode); + + /// + /// Serves as the default hash function. + /// + /// A hash code for the current object. + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value.GetHashCode(); + + /// + /// Returns a string representation of the TextAnalyticsErrorCode. + /// + /// The TextAnalyticsErrorCode as a string. + public override string ToString() => _value; + } +} diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsModelFactory.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsModelFactory.cs index cdfa0b0b893b3..aefad044bf471 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsModelFactory.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsModelFactory.cs @@ -41,7 +41,7 @@ public static TextDocumentBatchStatistics TextDocumentBatchStatistics(int docume /// /// Initializes a new instance of for mocking purposes. /// - /// Sets the property. + /// Sets the property. /// Sets the property. /// Sets the property. /// A new instance of for mocking purposes. diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsResult.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsResult.cs index 5da8636bcca5e..f6cbb31e61c6f 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsResult.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsResult.cs @@ -45,6 +45,6 @@ internal TextAnalyticsResult(string id, TextAnalyticsError error) /// /// Indicates that the document was not successfully processed and an error was returned for this document. /// - public bool HasError => Error.Code != default; + public bool HasError => Error.ErrorCode != default; } } diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsServiceSerializer.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsServiceSerializer.cs index 96c2ae62fe542..b732be8f14803 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsServiceSerializer.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsServiceSerializer.cs @@ -156,7 +156,7 @@ private static TextAnalyticsError ReadTextAnalyticsError(JsonElement element) } // Return the innermost error, which should be only one level down. - return innerError.Code == default ? new TextAnalyticsError(errorCode, message, target) : innerError; + return innerError.ErrorCode == default ? new TextAnalyticsError(errorCode, message, target) : innerError; } private static List ReadDocumentWarnings(JsonElement documentElement) diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsWarning.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsWarning.cs index c23fa2c61d1c0..89f08fcb6a7b5 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsWarning.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsWarning.cs @@ -17,7 +17,7 @@ internal TextAnalyticsWarning(string code, string message) /// /// Code indicating the type of warning. /// - public string WarningCode { get; } + public TextAnalyticsWarningCode WarningCode { get; } /// /// Message that contains more information about the reason of the warning. diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsWarningCode.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsWarningCode.cs new file mode 100644 index 0000000000000..3d2af83a8285a --- /dev/null +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/src/TextAnalyticsWarningCode.cs @@ -0,0 +1,91 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.ComponentModel; +using Azure.Core; + +namespace Azure.AI.TextAnalytics +{ + /// + /// Text Analytics warning code values. + /// + public readonly struct TextAnalyticsWarningCode : IEquatable + { + private readonly string _value; + + /// + /// Specifies that the warning code is long words in document. + /// + public static readonly string LongWordsInDocument = "LongWordsInDocument"; + + /// + /// Specifies that the warning code is a document truncated. + /// + public static readonly string DocumentTruncated = "DocumentTruncated"; + + private TextAnalyticsWarningCode(string warningCode) + { + Argument.AssertNotNullOrEmpty(warningCode, nameof(warningCode)); + _value = warningCode; + } + + /// + /// Defines implicit conversion from string to TextAnalyticsWarningCode. + /// + /// string to convert. + /// The string as an TextAnalyticsWarningCode. + public static implicit operator TextAnalyticsWarningCode(string warningCode) => new TextAnalyticsWarningCode(warningCode); + + /// + /// Defines explicit conversion from TextAnalyticsWarningCode to string. + /// + /// TextAnalyticsWarningCode to convert. + /// The TextAnalyticsWarningCode as a string. + public static explicit operator string(TextAnalyticsWarningCode warningCode) => warningCode._value; + + /// + /// Compares two TextAnalyticsWarningCode values for equality. + /// + /// The first TextAnalyticsWarningCode to compare. + /// The second TextAnalyticsWarningCode to compare. + /// true if the TextAnalyticsWarningCode objects are equal or are both null; false otherwise. + public static bool operator ==(TextAnalyticsWarningCode left, TextAnalyticsWarningCode right) => Equals(left, right); + + /// + /// Compares two TextAnalyticsWarningCode values for inequality. + /// + /// The first TextAnalyticsWarningCode to compare. + /// The second TextAnalyticsWarningCode to compare. + /// true if the TextAnalyticsWarningCode objects are not equal; false otherwise. + public static bool operator !=(TextAnalyticsWarningCode left, TextAnalyticsWarningCode right) => !Equals(left, right); + + /// + /// Compares the TextAnalyticsWarningCode for equality with another TextAnalyticsWarningCode. + /// + /// The TextAnalyticsWarningCode with which to compare. + /// true if the TextAnalyticsWarningCode objects are equal; otherwise, false. + public bool Equals(TextAnalyticsWarningCode other) => _value == other._value; + + /// + /// Determines whether the specified object is equal to the current object. + /// + /// The object to compare with the current object. + /// true if the specified object is equal to the current object; otherwise, false. + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is TextAnalyticsWarningCode warningCode && Equals(warningCode); + + /// + /// Serves as the default hash function. + /// + /// A hash code for the current object. + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value.GetHashCode(); + + /// + /// Returns a string representation of the TextAnalyticsWarningCode. + /// + /// The TextAnalyticsWarningCode as a string. + public override string ToString() => _value; + } +} diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/TextAnalyticsClientLiveTests.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/TextAnalyticsClientLiveTests.cs index 2238cebc13cc7..2eee0de68a627 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/TextAnalyticsClientLiveTests.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/TextAnalyticsClientLiveTests.cs @@ -447,7 +447,7 @@ public async Task ExtractKeyPhrasesWithWarningTest() Assert.IsNotNull(keyPhrases.Warnings); Assert.GreaterOrEqual(keyPhrases.Warnings.Count, 0); - Assert.AreEqual("LongWordsInDocument", keyPhrases.Warnings.FirstOrDefault().WarningCode); + Assert.AreEqual(TextAnalyticsWarningCode.LongWordsInDocument, keyPhrases.Warnings.FirstOrDefault().WarningCode.ToString()); Assert.GreaterOrEqual(keyPhrases.Count, 1); } diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/TextAnalyticsClientMockTests.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/TextAnalyticsClientMockTests.cs index f5cd0e2fd9cd1..1b1288eb0ffb4 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/TextAnalyticsClientMockTests.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/TextAnalyticsClientMockTests.cs @@ -165,7 +165,7 @@ private void SerializeRecognizeEntitiesResultCollection(ref Utf8JsonWriter json, foreach (var warning in result.Entities.Warnings) { json.WriteStartObject(); - json.WriteString("code", warning.WarningCode); + json.WriteString("code", warning.WarningCode.ToString()); json.WriteString("message", warning.Message); json.WriteEndObject(); } @@ -187,6 +187,7 @@ private void SerializeRecognizeEntitiesResultCollection(ref Utf8JsonWriter json, json.WriteString("id", result.Id); json.WriteStartObject("error"); json.WriteStartObject("innererror"); + json.WriteString("code", result.Error.ErrorCode.ToString()); json.WriteString("message", result.Error.Message); json.WriteEndObject(); json.WriteEndObject(); diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/TextAnalyticsErrorTests.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/TextAnalyticsErrorTests.cs index d4e1761e56a01..5d3dc9d2c5373 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/TextAnalyticsErrorTests.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/TextAnalyticsErrorTests.cs @@ -3,6 +3,7 @@ using Azure.Core.TestFramework; using NUnit.Framework; +using System; using System.Linq; using System.Text.Json; using System.Threading.Tasks; @@ -39,7 +40,7 @@ public void DeserializeTextAnalyticsError() Assert.IsNotNull(result); Assert.IsNotNull(result.Error); - Assert.AreEqual(result.Error.Code, "InvalidDocument"); + Assert.IsTrue(result.Error.ErrorCode.ToString().Equals(TextAnalyticsErrorCode.InvalidDocument, StringComparison.OrdinalIgnoreCase)); Assert.AreEqual(result.Error.Message, "Document text is empty."); } } diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample1_DetectLanguageBatch.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample1_DetectLanguageBatch.cs index 06357ea10f6c2..a0789f9e1ed3c 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample1_DetectLanguageBatch.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample1_DetectLanguageBatch.cs @@ -57,7 +57,7 @@ public void DetectLanguageBatch() if (result.HasError) { - Debug.WriteLine($" Document error code: {result.Error.Code}."); + Debug.WriteLine($" Document error code: {result.Error.ErrorCode}."); Debug.WriteLine($" Message: {result.Error.Message}."); } else diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample1_DetectLanguageBatchAsync.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample1_DetectLanguageBatchAsync.cs index b87ed6992e82d..bdd163e724a80 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample1_DetectLanguageBatchAsync.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample1_DetectLanguageBatchAsync.cs @@ -55,7 +55,7 @@ public async Task DetectLanguageBatchAsync() if (result.HasError) { - Console.WriteLine($" Document error code: {result.Error.Code}."); + Console.WriteLine($" Document error code: {result.Error.ErrorCode}."); Console.WriteLine($" Message: {result.Error.Message}."); } else diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample2_AnalyzeSentimentBatch.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample2_AnalyzeSentimentBatch.cs index 9297bf8b83efc..11d84b37bc9e4 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample2_AnalyzeSentimentBatch.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample2_AnalyzeSentimentBatch.cs @@ -57,7 +57,7 @@ public void AnalyzeSentimentBatch() if (result.HasError) { - Console.WriteLine($" Document error: {result.Error.Code}."); + Console.WriteLine($" Document error: {result.Error.ErrorCode}."); Console.WriteLine($" Message: {result.Error.Message}."); } else diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample2_AnalyzeSentimentBatchAsync.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample2_AnalyzeSentimentBatchAsync.cs index 80593840af65e..054bcef8fbf65 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample2_AnalyzeSentimentBatchAsync.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample2_AnalyzeSentimentBatchAsync.cs @@ -55,7 +55,7 @@ public async Task AnalyzeSentimentBatchAsync() if (result.HasError) { - Console.WriteLine($" Document error: {result.Error.Code}."); + Console.WriteLine($" Document error: {result.Error.ErrorCode}."); Console.WriteLine($" Message: {result.Error.Message}."); } else diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample2_AnalyzeSentimentBatchConvenienceAsync.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample2_AnalyzeSentimentBatchConvenienceAsync.cs index 1e5b3a63e5739..aedcd2ba934cf 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample2_AnalyzeSentimentBatchConvenienceAsync.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample2_AnalyzeSentimentBatchConvenienceAsync.cs @@ -41,7 +41,7 @@ public async Task AnalyzeSentimentBatchConvenienceAsync() if (result.HasError) { - Console.WriteLine($" Document error: {result.Error.Code}."); + Console.WriteLine($" Document error: {result.Error.ErrorCode}."); Console.WriteLine($" Message: {result.Error.Message}."); } else diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample3_ExtractKeyPhrasesBatch.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample3_ExtractKeyPhrasesBatch.cs index 29b0cce6be219..e2f536ab7508c 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample3_ExtractKeyPhrasesBatch.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample3_ExtractKeyPhrasesBatch.cs @@ -54,7 +54,7 @@ public void ExtractKeyPhrasesBatch() if (result.HasError) { - Debug.WriteLine($" Document error: {result.Error.Code}."); + Debug.WriteLine($" Document error: {result.Error.ErrorCode}."); Debug.WriteLine($" Message: {result.Error.Message}."); } else diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample3_ExtractKeyPhrasesBatchAsync.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample3_ExtractKeyPhrasesBatchAsync.cs index bf786be56058b..76c7665682ece 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample3_ExtractKeyPhrasesBatchAsync.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample3_ExtractKeyPhrasesBatchAsync.cs @@ -52,7 +52,7 @@ public async Task ExtractKeyPhrasesBatchAsync() if (result.HasError) { - Console.WriteLine($" Document error: {result.Error.Code}."); + Console.WriteLine($" Document error: {result.Error.ErrorCode}."); Console.WriteLine($" Message: {result.Error.Message}."); } else diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample4_RecognizeEntitiesBatch.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample4_RecognizeEntitiesBatch.cs index 8f8e8567d72e7..2ceccb4488ac4 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample4_RecognizeEntitiesBatch.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample4_RecognizeEntitiesBatch.cs @@ -54,7 +54,7 @@ public void RecognizeEntitiesBatch() if (result.HasError) { - Debug.WriteLine($" Document error code: {result.Error.Code}."); + Debug.WriteLine($" Document error code: {result.Error.ErrorCode}."); Debug.WriteLine($" Message: {result.Error.Message}."); } else diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample4_RecognizeEntitiesBatchAsync.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample4_RecognizeEntitiesBatchAsync.cs index a61b5242729a7..0753e3413e275 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample4_RecognizeEntitiesBatchAsync.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample4_RecognizeEntitiesBatchAsync.cs @@ -52,7 +52,7 @@ public async Task RecognizeEntitiesBatchAsync() if (result.HasError) { - Console.WriteLine($" Document error code: {result.Error.Code}."); + Console.WriteLine($" Document error code: {result.Error.ErrorCode}."); Console.WriteLine($" Message: {result.Error.Message}."); } else diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample6_RecognizeLinkedEntitiesBatch.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample6_RecognizeLinkedEntitiesBatch.cs index 11d19d9244d6b..5bcb7a9ca7579 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample6_RecognizeLinkedEntitiesBatch.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample6_RecognizeLinkedEntitiesBatch.cs @@ -54,7 +54,7 @@ public void ExtractEntityLinkingBatch() if (result.HasError) { - Debug.WriteLine($" Document error code: {result.Error.Code}."); + Debug.WriteLine($" Document error code: {result.Error.ErrorCode}."); Debug.WriteLine($" Message: {result.Error.Message}."); } else diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample6_RecognizeLinkedEntitiesBatchAsync.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample6_RecognizeLinkedEntitiesBatchAsync.cs index 49f37d3696b52..e07fb27c4e2b7 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample6_RecognizeLinkedEntitiesBatchAsync.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample6_RecognizeLinkedEntitiesBatchAsync.cs @@ -52,7 +52,7 @@ public async Task ExtractEntityLinkingBatchAsync() if (result.HasError) { - Console.WriteLine($" Document error code: {result.Error.Code}."); + Console.WriteLine($" Document error code: {result.Error.ErrorCode}."); Console.WriteLine($" Message: {result.Error.Message}."); } else