Skip to content

Commit d2230f8

Browse files
committed
fix: throw correct exception type when we can't verify if an s3 bucket exists
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent 852ae27 commit d2230f8

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

lib/private/Files/ObjectStore/S3ConnectionTrait.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
use Aws\S3\S3Client;
4141
use GuzzleHttp\Promise;
4242
use GuzzleHttp\Promise\RejectedPromise;
43+
use OCP\Files\StorageNotAvailableException;
4344
use OCP\ICertificateManager;
4445
use OCP\Server;
4546
use Psr\Log\LoggerInterface;
@@ -155,12 +156,12 @@ public function getConnection() {
155156
$logger->debug('Bucket "' . $this->bucket . '" This bucket name is not dns compatible, it may contain invalid characters.',
156157
['app' => 'objectstore']);
157158
}
158-
159+
159160
if ($this->params['verify_bucket_exists'] && !$this->connection->doesBucketExist($this->bucket)) {
160161
try {
161162
$logger->info('Bucket "' . $this->bucket . '" does not exist - creating it.', ['app' => 'objectstore']);
162163
if (!$this->connection::isBucketDnsCompatible($this->bucket)) {
163-
throw new \Exception("The bucket will not be created because the name is not dns compatible, please correct it: " . $this->bucket);
164+
throw new StorageNotAvailableException("The bucket will not be created because the name is not dns compatible, please correct it: " . $this->bucket);
164165
}
165166
$this->connection->createBucket(['Bucket' => $this->bucket]);
166167
$this->testTimeout();
@@ -170,17 +171,17 @@ public function getConnection() {
170171
'app' => 'objectstore',
171172
]);
172173
if ($e->getAwsErrorCode() !== 'BucketAlreadyOwnedByYou') {
173-
throw new \Exception('Creation of bucket "' . $this->bucket . '" failed. ' . $e->getMessage());
174+
throw new StorageNotAvailableException('Creation of bucket "' . $this->bucket . '" failed. ' . $e->getMessage());
174175
}
175176
}
176177
}
177-
178+
178179
// google cloud's s3 compatibility doesn't like the EncodingType parameter
179180
if (strpos($base_url, 'storage.googleapis.com')) {
180181
$this->connection->getHandlerList()->remove('s3.auto_encode');
181182
}
182183
} catch (S3Exception $e) {
183-
throw new \Exception('S3 service is unable to handle request: ' . $e->getMessage());
184+
throw new StorageNotAvailableException('S3 service is unable to handle request: ' . $e->getMessage());
184185
}
185186

186187
return $this->connection;

0 commit comments

Comments
 (0)