< Summary

Class:Azure.Storage.StorageExceptionExtensions
Assembly:Azure.Storage.Files.DataLake
File(s):C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Common\src\Shared\StorageExceptionExtensions.cs
Covered lines:3
Uncovered lines:2
Coverable lines:5
Total lines:52
Line coverage:60% (3 of 5)
Covered branches:2
Total branches:4
Branch coverage:50% (2 of 4)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
GetErrorCode(...)-100%100%
IsUnavailable(...)-0%0%
AsNoBodyResponse(...)-0%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Common\src\Shared\StorageExceptionExtensions.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 Azure.Core;
 9
 10namespace Azure.Storage
 11{
 12    /// <summary>
 13    /// Provide helpful information about errors calling Azure Storage endpoints.
 14    /// </summary>
 15    internal static class StorageExceptionExtensions
 16    {
 17        /// <summary>
 18        /// Attempt to get the error code from a response if it's not provided.
 19        /// </summary>
 20        /// <param name="response">The response.</param>
 21        /// <param name="errorCode">An optional error code.</param>
 22        /// <returns>The response's error code.</returns>
 23        public static string GetErrorCode(this Response response, string errorCode)
 24        {
 1225            if (string.IsNullOrEmpty(errorCode))
 26            {
 1227                response.Headers.TryGetValue(Constants.HeaderNames.ErrorCode, out errorCode);
 28            }
 1229            return errorCode;
 30        }
 31
 32        /// <summary>
 33        /// Check if a Response will throw an exception if you try to access
 34        /// its Value property.
 35        /// </summary>
 36        /// <typeparam name="T">Type of the Response Value.</typeparam>
 37        /// <param name="response">The response to check.</param>
 38        /// <returns>True if the response will throw.</returns>
 39        public static bool IsUnavailable<T>(this Response<T> response) =>
 040            (response?.GetRawResponse().Status ?? 0) == 304;
 41
 42        /// <summary>
 43        /// Create a response that will throw an exception if you try to access
 44        /// its Value property.
 45        /// </summary>
 46        /// <typeparam name="T">Type of the Response Value.</typeparam>
 47        /// <param name="rawResponse">The raw response.</param>
 48        /// <returns>A response that will throw if accessed.</returns>
 49        public static Response<T> AsNoBodyResponse<T>(this Response rawResponse) =>
 050            new NoBodyResponse<T>(rawResponse);
 51    }
 52}