Skip to content

Commit df3a9e2

Browse files
committed
fix: throw correct exception type when we can't verify if an s3 bucket exists
Signed-off-by: Robin Appelman <[email protected]>
1 parent 14f7e56 commit df3a9e2

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

lib/private/Files/ObjectStore/S3ConnectionTrait.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Aws\S3\S3Client;
1414
use GuzzleHttp\Promise\Create;
1515
use GuzzleHttp\Promise\RejectedPromise;
16+
use OCP\Files\StorageNotAvailableException;
1617
use OCP\ICertificateManager;
1718
use OCP\Server;
1819
use Psr\Log\LoggerInterface;
@@ -132,7 +133,7 @@ public function getConnection() {
132133
try {
133134
$logger->info('Bucket "' . $this->bucket . '" does not exist - creating it.', ['app' => 'objectstore']);
134135
if (!$this->connection::isBucketDnsCompatible($this->bucket)) {
135-
throw new \Exception('The bucket will not be created because the name is not dns compatible, please correct it: ' . $this->bucket);
136+
throw new StorageNotAvailableException('The bucket will not be created because the name is not dns compatible, please correct it: ' . $this->bucket);
136137
}
137138
$this->connection->createBucket(['Bucket' => $this->bucket]);
138139
$this->testTimeout();
@@ -142,17 +143,17 @@ public function getConnection() {
142143
'app' => 'objectstore',
143144
]);
144145
if ($e->getAwsErrorCode() !== 'BucketAlreadyOwnedByYou') {
145-
throw new \Exception('Creation of bucket "' . $this->bucket . '" failed. ' . $e->getMessage());
146+
throw new StorageNotAvailableException('Creation of bucket "' . $this->bucket . '" failed. ' . $e->getMessage());
146147
}
147148
}
148149
}
149-
150+
150151
// google cloud's s3 compatibility doesn't like the EncodingType parameter
151152
if (strpos($base_url, 'storage.googleapis.com')) {
152153
$this->connection->getHandlerList()->remove('s3.auto_encode');
153154
}
154155
} catch (S3Exception $e) {
155-
throw new \Exception('S3 service is unable to handle request: ' . $e->getMessage());
156+
throw new StorageNotAvailableException('S3 service is unable to handle request: ' . $e->getMessage());
156157
}
157158

158159
return $this->connection;

0 commit comments

Comments
 (0)