diff options
author | Robin Appelman <robin@icewind.nl> | 2024-11-26 16:49:55 +0100 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2024-11-26 16:49:55 +0100 |
commit | df3a9e221d08d7e114da0a52994e6e2e43decc8a (patch) | |
tree | cb762cd1604aabc0122dff3277cd8d445f67f77d /lib | |
parent | 14f7e566c4cfca78d22706321b8f0b6cf4878ddb (diff) | |
download | nextcloud-server-df3a9e221d08d7e114da0a52994e6e2e43decc8a.tar.gz nextcloud-server-df3a9e221d08d7e114da0a52994e6e2e43decc8a.zip |
fix: throw correct exception type when we can't verify if an s3 bucket exists
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Files/ObjectStore/S3ConnectionTrait.php | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/lib/private/Files/ObjectStore/S3ConnectionTrait.php b/lib/private/Files/ObjectStore/S3ConnectionTrait.php index 9de85f00620..cce8752c360 100644 --- a/lib/private/Files/ObjectStore/S3ConnectionTrait.php +++ b/lib/private/Files/ObjectStore/S3ConnectionTrait.php @@ -13,6 +13,7 @@ use Aws\S3\Exception\S3Exception; use Aws\S3\S3Client; use GuzzleHttp\Promise\Create; use GuzzleHttp\Promise\RejectedPromise; +use OCP\Files\StorageNotAvailableException; use OCP\ICertificateManager; use OCP\Server; use Psr\Log\LoggerInterface; @@ -132,7 +133,7 @@ trait S3ConnectionTrait { try { $logger->info('Bucket "' . $this->bucket . '" does not exist - creating it.', ['app' => 'objectstore']); if (!$this->connection::isBucketDnsCompatible($this->bucket)) { - throw new \Exception('The bucket will not be created because the name is not dns compatible, please correct it: ' . $this->bucket); + throw new StorageNotAvailableException('The bucket will not be created because the name is not dns compatible, please correct it: ' . $this->bucket); } $this->connection->createBucket(['Bucket' => $this->bucket]); $this->testTimeout(); @@ -142,17 +143,17 @@ trait S3ConnectionTrait { 'app' => 'objectstore', ]); if ($e->getAwsErrorCode() !== 'BucketAlreadyOwnedByYou') { - throw new \Exception('Creation of bucket "' . $this->bucket . '" failed. ' . $e->getMessage()); + throw new StorageNotAvailableException('Creation of bucket "' . $this->bucket . '" failed. ' . $e->getMessage()); } } } - + // google cloud's s3 compatibility doesn't like the EncodingType parameter if (strpos($base_url, 'storage.googleapis.com')) { $this->connection->getHandlerList()->remove('s3.auto_encode'); } } catch (S3Exception $e) { - throw new \Exception('S3 service is unable to handle request: ' . $e->getMessage()); + throw new StorageNotAvailableException('S3 service is unable to handle request: ' . $e->getMessage()); } return $this->connection; |