示例#1
0
 public static void ValidateUrl(string url, bool isUserProvided = true)
 {
     try
     {
         var response = TryGetResponse(url);
         response.Close();
     }
     catch (Exception)
     {
         if (isUserProvided)
         {
             throw new UserErrorException($"Unable to validate the URL for {UrlUtilities.GetFileName(url)}");
         }
         throw new DeploymentErrorException($"Deployment issue detected. Unable to validate the URL for {url}.");
     }
 }
示例#2
0
        public static Exception ProcessHttpRequestWebProtocolErrorException(Exception exception, string url)
        {
            if (!IsWebProtocolErrorException(exception))
            {
                return(exception);
            }

            string urlPath = UrlUtilities.GetPath(url);

            var webException = (WebException)exception;

            (string errorCode, string errorMessage) = GetWebExceptionMessage(webException);

            // Expired URL is always a user error
            if (errorMessage == "Request has expired")
            {
                return(new UserErrorException($"The provided URL for {urlPath} has expired."));
            }

            // Authentication error is always considered as a user error
            if (AuthenticationErrorCodes.Contains(errorCode))
            {
                return(new UserErrorException($"Authentication error while reading from URL for {urlPath}."));
            }

            // Resource not exist error is always considered as a user error
            if (ResourceNotExistErrorCodes.Contains(errorCode))
            {
                return(new UserErrorException($"An invalid URL for {urlPath} was specified."));
            }

            // Sometimes it is difficult to figure out whether the error is caused by the user or not.
            // For example, the AccessDenied error code could be triggered by either incorrect credentials provided by the user, or network congestion while reading from S3.
            // Therefore, such errors are treated as general exceptions.
            // And we don't pass through the general error to end user to avoid possible confusion.
            Logger.WriteLine($"The following error occurred while reading from {url}: {errorMessage}. Exception: {exception.Message}");
            return(new WebException($"An error occurred while reading from the URL for {urlPath} ({exception.GetType()})"));
        }