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;
}