Microsoft.Protocols.TestSuites.Common.Common.GetErrorCodeFromException C# (CSharp) Method

GetErrorCodeFromException() public static method

Get status code from web exception which will be returned by IIS.
public static GetErrorCodeFromException ( WebException webException ) : string
webException System.Net.WebException Web exception
return string
        public static string GetErrorCodeFromException(WebException webException)
        {
            if (null == webException)
            {
                return string.Empty;
            }

            string exceptionMessage = webException.Message;
            string statusCode = string.Empty;
            if (exceptionMessage.Contains("(") && exceptionMessage.Contains(")"))
            {
                int leftParenthesis = exceptionMessage.IndexOf("(", StringComparison.CurrentCultureIgnoreCase);
                int rightParenthesis = exceptionMessage.IndexOf(")", StringComparison.CurrentCultureIgnoreCase);
                statusCode = exceptionMessage.Substring(leftParenthesis + 1, rightParenthesis - leftParenthesis - 1);
            }

            return statusCode;
        }
Common