Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update metadata message signifying item not found #193

Merged
merged 4 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Storage/Internal/StorageDataClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Grpc\UnaryCall;
use Momento\Auth\ICredentialProvider;
use Momento\Cache\CacheOperationTypes\ResponseFuture;
use Momento\Cache\Errors\CacheNotFoundError;
use Momento\Cache\Errors\ItemNotFoundError;
use Momento\Cache\Errors\SdkError;
use Momento\Cache\Errors\StoreNotFoundError;
Expand Down
11 changes: 10 additions & 1 deletion src/Storage/PreviewStorageClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@

use Momento\Auth\ICredentialProvider;
use Momento\Cache\CacheOperationTypes\ResponseFuture;
use Momento\Cache\Errors\CacheNotFoundError;
use Momento\Cache\Errors\InvalidArgumentError;
use Momento\Cache\Errors\MomentoErrorCode;
use Momento\Cache\Errors\StoreNotFoundError;
use Momento\Cache\Internal\IdleStorageDataClientWrapper;
use Momento\Cache\Internal\ScsControlClient;
use Momento\Config\IStorageConfiguration;
use Momento\Logging\ILoggerFactory;
use Momento\Storage\Internal\StorageDataClient;
use Momento\Storage\StorageOperationTypes\CreateStoreResponse;
use Momento\Storage\StorageOperationTypes\DeleteStoreError;
use Momento\Storage\StorageOperationTypes\DeleteStoreResponse;
use Momento\Storage\StorageOperationTypes\ListStoresResponse;
use Momento\Storage\StorageOperationTypes\StorageDeleteResponse;
Expand Down Expand Up @@ -153,7 +157,12 @@ public function listStores(): ListStoresResponse
*/
public function deleteStore(string $storeName): DeleteStoreResponse
{
return $this->controlClient->deleteStore($storeName);
$response = $this->controlClient->deleteStore($storeName);
if ($response->asError() && $response->asError()->errorCode() == MomentoErrorCode::CACHE_NOT_FOUND_ERROR) {
$this->logger->info("Store $storeName does not exist.");
return new DeleteStoreError(new StoreNotFoundError("Store $storeName does not exist."));
}
return $response;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Utilities/_ErrorConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static function convert($grpcStatus, ?array $metadata = null): SdkError
$class = CacheNotFoundError::class;
} elseif ($grpcStatus->metadata["err"][0] == "store_not_found") {
$class = StoreNotFoundError::class;
} elseif ($grpcStatus->metadata["err"][0] == "element_not_found") {
} elseif ($grpcStatus->metadata["err"][0] == "item_not_found") {
$class = ItemNotFoundError::class;
} else {
$class = CacheNotFoundError::class;
Expand Down
9 changes: 8 additions & 1 deletion tests/Storage/StorageClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

use Momento\Auth\EnvMomentoTokenProvider;
use Momento\Cache\Errors\MomentoErrorCode;
use Momento\Cache\Errors\NotFoundError;
use Momento\Cache\Errors\StoreNotFoundError;
use Momento\Config\IStorageConfiguration;
use Momento\Config\Configurations;
Expand Down Expand Up @@ -146,6 +145,14 @@ public function testDeleteStoreNullName()
$this->client->deleteStore(null);
}

public function testDeleteNonexistentStore()
{
$storeName = uniqid();
$response = $this->client->deleteStore($storeName);
$this->assertNotNull($response->asError());
$this->assertEquals(MomentoErrorCode::STORE_NOT_FOUND_ERROR, $response->asError()->errorCode());
}

public function testStoreNotFound()
{
$storeName = uniqid();
Expand Down
Loading