partial void ExtractFailureContent( string?content, ResponseHeaders responseHeaders, ref string?message, ref string?errorCode, ref IDictionary <string, string>?additionalInfo) #pragma warning restore CA1801 // Remove unused parameter #pragma warning restore CA1822 // Member can be static { if (!string.IsNullOrEmpty(content)) { try { // Try to parse the failure content and use that as the // default value for the message, error code, etc. using JsonDocument doc = JsonDocument.Parse(content); if (doc.RootElement.TryGetProperty("error", out JsonElement errorElement)) { DocumentTranslationError error = DocumentTranslationError.DeserializeDocumentTranslationError(errorElement); message = error.Message; errorCode = error.ErrorCode.ToString(); } } catch (JsonException) { // Ignore any failures - unexpected content will be // included verbatim in the detailed error message } } }
internal static TranslationErrorResponse DeserializeTranslationErrorResponse(JsonElement element) { Optional <DocumentTranslationError> error = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("error")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } error = DocumentTranslationError.DeserializeDocumentTranslationError(property.Value); continue; } } return(new TranslationErrorResponse(Optional.ToNullable(error))); }