Skip to content

Commit

Permalink
fix: throw correct exception type when we can't verify if an s3 bucke…
Browse files Browse the repository at this point in the history
…t exists

Signed-off-by: Robin Appelman <robin@icewind.nl>
  • Loading branch information
icewind1991 committed Nov 26, 2024
1 parent 14f7e56 commit df3a9e2
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/private/Files/ObjectStore/S3ConnectionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
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;
Expand Down Expand Up @@ -132,7 +133,7 @@ public function getConnection() {
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();
Expand All @@ -142,17 +143,17 @@ public function getConnection() {
'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;
Expand Down

0 comments on commit df3a9e2

Please sign in to comment.