Skip to content

Commit 228cfb3

Browse files
authored
Merge pull request #72 from tinect/fix/ignore404OnDelete
2 parents 30cc7fc + afb885b commit 228cfb3

File tree

5 files changed

+7
-18
lines changed

5 files changed

+7
-18
lines changed

src/BunnyCDNAdapter.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use League\Flysystem\UrlGeneration\PublicUrlGenerator;
2828
use League\Flysystem\Visibility;
2929
use League\MimeTypeDetection\FinfoMimeTypeDetector;
30+
use PlatformCommunity\Flysystem\BunnyCDN\Exceptions\NotFoundException;
3031
use RuntimeException;
3132
use TypeError;
3233

@@ -252,6 +253,8 @@ public function deleteDirectory(string $path): void
252253
rtrim($path, '/').'/'
253254
);
254255
// @codeCoverageIgnoreStart
256+
} catch (NotFoundException) {
257+
// nth
255258
} catch (Exceptions\BunnyCDNException $e) {
256259
throw UnableToDeleteDirectory::atLocation($path, $e->getMessage());
257260
}
@@ -462,10 +465,10 @@ public function delete($path): void
462465
try {
463466
$this->client->delete($path);
464467
// @codeCoverageIgnoreStart
468+
} catch (NotFoundException) {
469+
// nth
465470
} catch (Exceptions\BunnyCDNException $e) {
466-
if (! str_contains($e->getMessage(), '404')) { // Urgh
467-
throw UnableToDeleteFile::atLocation($path, $e->getMessage());
468-
}
471+
throw UnableToDeleteFile::atLocation($path, $e->getMessage());
469472
}
470473
// @codeCoverageIgnoreEnd
471474
}

src/BunnyCDNClient.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use GuzzleHttp\Client as Guzzle;
66
use GuzzleHttp\Exception\GuzzleException;
77
use PlatformCommunity\Flysystem\BunnyCDN\Exceptions\BunnyCDNException;
8-
use PlatformCommunity\Flysystem\BunnyCDN\Exceptions\DirectoryNotEmptyException;
98
use PlatformCommunity\Flysystem\BunnyCDN\Exceptions\NotFoundException;
109

1110
class BunnyCDNClient
@@ -204,7 +203,7 @@ public function make_directory(string $path): mixed
204203
* @return mixed
205204
*
206205
* @throws NotFoundException
207-
* @throws DirectoryNotEmptyException|BunnyCDNException
206+
* @throws BunnyCDNException
208207
*/
209208
public function delete(string $path): mixed
210209
{
@@ -214,7 +213,6 @@ public function delete(string $path): mixed
214213
} catch (GuzzleException $e) {
215214
throw match ($e->getCode()) {
216215
404 => new NotFoundException($e->getMessage()),
217-
400 => new DirectoryNotEmptyException($e->getMessage()),
218216
default => new BunnyCDNException($e->getMessage())
219217
};
220218
}

src/Exceptions/DirectoryNotEmptyException.php

Lines changed: 0 additions & 7 deletions
This file was deleted.

tests/ClientTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use PlatformCommunity\Flysystem\BunnyCDN\BunnyCDNClient;
88
use PlatformCommunity\Flysystem\BunnyCDN\BunnyCDNRegion;
99
use PlatformCommunity\Flysystem\BunnyCDN\Exceptions\BunnyCDNException;
10-
use PlatformCommunity\Flysystem\BunnyCDN\Exceptions\DirectoryNotEmptyException;
1110
use PlatformCommunity\Flysystem\BunnyCDN\Exceptions\NotFoundException;
1211

1312
if (\is_file(__DIR__.'/ClientDI.php')) {
@@ -167,7 +166,6 @@ public function test_make_directory()
167166
* @return void
168167
*
169168
* @throws BunnyCDNException
170-
* @throws DirectoryNotEmptyException
171169
* @throws NotFoundException
172170
*/
173171
public function test_delete_file()
@@ -187,7 +185,6 @@ public function test_delete_file()
187185
* @return void
188186
*
189187
* @throws BunnyCDNException
190-
* @throws DirectoryNotEmptyException
191188
* @throws NotFoundException
192189
*/
193190
public function test_delete_file_not_found()

tests/MockClient.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use League\Flysystem\StorageAttributes;
1111
use PlatformCommunity\Flysystem\BunnyCDN\BunnyCDNClient;
1212
use PlatformCommunity\Flysystem\BunnyCDN\Exceptions\BunnyCDNException;
13-
use PlatformCommunity\Flysystem\BunnyCDN\Exceptions\DirectoryNotEmptyException;
1413
use PlatformCommunity\Flysystem\BunnyCDN\Exceptions\NotFoundException;
1514
use PlatformCommunity\Flysystem\BunnyCDN\Util;
1615

@@ -109,7 +108,6 @@ public function make_directory(string $path): array
109108
*
110109
* @throws FilesystemException
111110
* @throws BunnyCDNException
112-
* @throws DirectoryNotEmptyException
113111
* @throws NotFoundException
114112
*/
115113
public function delete(string $path): array

0 commit comments

Comments
 (0)