< Summary

Class:Azure.Storage.Files.DataLake.ErrorExtensions
Assembly:Azure.Storage.Files.DataLake
File(s):C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Files.DataLake\src\ErrorExtensions.cs
Covered lines:28
Uncovered lines:0
Coverable lines:28
Total lines:68
Line coverage:100% (28 of 28)
Covered branches:12
Total branches:12
Branch coverage:100% (12 of 12)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
CreateException(...)-100%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Files.DataLake\src\ErrorExtensions.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using System.Collections.Generic;
 6using System.Globalization;
 7using System.Text;
 8using System.Text.Json;
 9using System.Xml.Linq;
 10using Azure.Core.Pipeline;
 11using Azure.Storage.Files.DataLake.Models;
 12
 13namespace Azure.Storage.Files.DataLake
 14{
 15    internal static class ErrorExtensions
 16    {
 17// clientDiagnostics parameter is a pattern expected by the codegenerator
 18#pragma warning disable CA1801
 19        internal static Exception CreateException(this string body, ClientDiagnostics clientDiagnostics, Response respon
 20#pragma warning restore CA1801
 21        {
 22            // xml
 43223            if (response.Headers.ContentType != null
 43224                && response.Headers.ContentType.Contains("application/xml"))
 25            {
 426                XElement error = XDocument.Parse(body).Element("Error");
 427                string code = error.Element("Code").Value.ToString(CultureInfo.InvariantCulture);
 428                string message = error.Element("Message").Value.ToString(CultureInfo.InvariantCulture);
 429                return clientDiagnostics.CreateRequestFailedExceptionWithContent(
 430                    response: response,
 431                    message: message,
 432                    errorCode: code);
 33            }
 34            // json
 42835            else if (response.Headers.ContentType != null
 42836                && response.Headers.ContentType.Contains("application/json"))
 37            {
 42038                JsonDocument json = JsonDocument.Parse(body);
 42039                JsonElement error = json.RootElement.GetProperty("error");
 40
 42041                IDictionary<string, string> details = default;
 42042                if (error.TryGetProperty("detail", out JsonElement detail))
 43                {
 444                    details = new Dictionary<string, string>();
 2445                    foreach (JsonProperty property in detail.EnumerateObject())
 46                    {
 847                        details[property.Name] = property.Value.GetString();
 48                    }
 49                }
 50
 42051                return clientDiagnostics.CreateRequestFailedExceptionWithContent(
 42052                    response: response,
 42053                    message: error.GetProperty("message").GetString(),
 42054                    errorCode: error.GetProperty("code").GetString(),
 42055                    additionalInfo: details);
 56            }
 57            else
 58            {
 859                return new RequestFailedException(
 860                    status: response.Status,
 861                    errorCode: response.Status.ToString(CultureInfo.InvariantCulture),
 862                    message: response.ReasonPhrase,
 863                    innerException: new Exception());
 64            }
 65        }
 66
 67    }
 68}

Methods/Properties

CreateException(...)