4040use Aws \S3 \S3Client ;
4141use GuzzleHttp \Promise ;
4242use GuzzleHttp \Promise \RejectedPromise ;
43+ use OCP \Files \StorageNotAvailableException ;
4344use OCP \ICertificateManager ;
4445use OCP \Server ;
4546use 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