Пример #1
0
        public static Exception TryConvertUserException(Exception exception, S3Path s3Path)
        {
            AmazonS3Exception s3Exception;

            while ((s3Exception = exception as AmazonS3Exception) == null)
            {
                if (exception.InnerException == null)
                {
                    return(exception);
                }
                exception = exception.InnerException;
            }

            string extraInfo;

            switch (s3Exception.ErrorCode)
            {
            case "ExpiredToken":
            case "InvalidToken":
                extraInfo = s3Path?.sessionToken;
                break;

            case "InvalidAccessKeyId":
                extraInfo = s3Path?.accessKey;
                break;

            case "SignatureDoesNotMatch":
                extraInfo = s3Path?.secretKey;
                break;

            case "NoSuchBucket":
                extraInfo = s3Path?.bucketName;
                break;

            case "AccessDenied":
            case "NoSuchKey":
                extraInfo = s3Path?.path;
                break;

            default:
                return(s3Exception);
            }

            string errorMessage = extraInfo == null
                ? s3Exception.Message
                : $"{s3Exception.Message} ({extraInfo})";

            return(new UserErrorException(errorMessage));
        }
Пример #2
0
 public void FormatPath_AsExpected()
 {
     Assert.Equal("to/the/file", S3Path.FormatPath("/to/the/file"));
     Assert.Equal("to/the/directory/", S3Path.FormatPath("/to/the/directory/"));
 }
Пример #3
0
 public void ValidatePathFormat_AsExpected(string path, bool isDirectory)
 {
     Assert.Throws <UserErrorException>(() => S3Path.ValidatePathFormat(path, isDirectory));
 }