Skip to content

Commit

Permalink
Merge pull request #72 from tinect/fix/ignore404OnDelete
Browse files Browse the repository at this point in the history
  • Loading branch information
sifex authored Apr 23, 2024
2 parents 30cc7fc + afb885b commit 228cfb3
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 18 deletions.
9 changes: 6 additions & 3 deletions src/BunnyCDNAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use League\Flysystem\UrlGeneration\PublicUrlGenerator;
use League\Flysystem\Visibility;
use League\MimeTypeDetection\FinfoMimeTypeDetector;
use PlatformCommunity\Flysystem\BunnyCDN\Exceptions\NotFoundException;
use RuntimeException;
use TypeError;

Expand Down Expand Up @@ -252,6 +253,8 @@ public function deleteDirectory(string $path): void
rtrim($path, '/').'/'
);
// @codeCoverageIgnoreStart
} catch (NotFoundException) {
// nth
} catch (Exceptions\BunnyCDNException $e) {
throw UnableToDeleteDirectory::atLocation($path, $e->getMessage());
}
Expand Down Expand Up @@ -462,10 +465,10 @@ public function delete($path): void
try {
$this->client->delete($path);
// @codeCoverageIgnoreStart
} catch (NotFoundException) {
// nth
} catch (Exceptions\BunnyCDNException $e) {
if (! str_contains($e->getMessage(), '404')) { // Urgh
throw UnableToDeleteFile::atLocation($path, $e->getMessage());
}
throw UnableToDeleteFile::atLocation($path, $e->getMessage());
}
// @codeCoverageIgnoreEnd
}
Expand Down
4 changes: 1 addition & 3 deletions src/BunnyCDNClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use GuzzleHttp\Client as Guzzle;
use GuzzleHttp\Exception\GuzzleException;
use PlatformCommunity\Flysystem\BunnyCDN\Exceptions\BunnyCDNException;
use PlatformCommunity\Flysystem\BunnyCDN\Exceptions\DirectoryNotEmptyException;
use PlatformCommunity\Flysystem\BunnyCDN\Exceptions\NotFoundException;

class BunnyCDNClient
Expand Down Expand Up @@ -204,7 +203,7 @@ public function make_directory(string $path): mixed
* @return mixed
*
* @throws NotFoundException
* @throws DirectoryNotEmptyException|BunnyCDNException
* @throws BunnyCDNException
*/
public function delete(string $path): mixed
{
Expand All @@ -214,7 +213,6 @@ public function delete(string $path): mixed
} catch (GuzzleException $e) {
throw match ($e->getCode()) {
404 => new NotFoundException($e->getMessage()),
400 => new DirectoryNotEmptyException($e->getMessage()),
default => new BunnyCDNException($e->getMessage())
};
}
Expand Down
7 changes: 0 additions & 7 deletions src/Exceptions/DirectoryNotEmptyException.php

This file was deleted.

3 changes: 0 additions & 3 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use PlatformCommunity\Flysystem\BunnyCDN\BunnyCDNClient;
use PlatformCommunity\Flysystem\BunnyCDN\BunnyCDNRegion;
use PlatformCommunity\Flysystem\BunnyCDN\Exceptions\BunnyCDNException;
use PlatformCommunity\Flysystem\BunnyCDN\Exceptions\DirectoryNotEmptyException;
use PlatformCommunity\Flysystem\BunnyCDN\Exceptions\NotFoundException;

if (\is_file(__DIR__.'/ClientDI.php')) {
Expand Down Expand Up @@ -167,7 +166,6 @@ public function test_make_directory()
* @return void
*
* @throws BunnyCDNException
* @throws DirectoryNotEmptyException
* @throws NotFoundException
*/
public function test_delete_file()
Expand All @@ -187,7 +185,6 @@ public function test_delete_file()
* @return void
*
* @throws BunnyCDNException
* @throws DirectoryNotEmptyException
* @throws NotFoundException
*/
public function test_delete_file_not_found()
Expand Down
2 changes: 0 additions & 2 deletions tests/MockClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use League\Flysystem\StorageAttributes;
use PlatformCommunity\Flysystem\BunnyCDN\BunnyCDNClient;
use PlatformCommunity\Flysystem\BunnyCDN\Exceptions\BunnyCDNException;
use PlatformCommunity\Flysystem\BunnyCDN\Exceptions\DirectoryNotEmptyException;
use PlatformCommunity\Flysystem\BunnyCDN\Exceptions\NotFoundException;
use PlatformCommunity\Flysystem\BunnyCDN\Util;

Expand Down Expand Up @@ -109,7 +108,6 @@ public function make_directory(string $path): array
*
* @throws FilesystemException
* @throws BunnyCDNException
* @throws DirectoryNotEmptyException
* @throws NotFoundException
*/
public function delete(string $path): array
Expand Down

0 comments on commit 228cfb3

Please sign in to comment.