< Summary

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

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
GetErrorCode(...)-66.67%50%
IsUnavailable(...)-100%50%
AsNoBodyResponse(...)-100%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        {
 201225            if (string.IsNullOrEmpty(errorCode))
 26            {
 027                response.Headers.TryGetValue(Constants.HeaderNames.ErrorCode, out errorCode);
 28            }
 201229            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) =>
 322440            (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) =>
 4450            new NoBodyResponse<T>(rawResponse);
 51    }
 52}