From ee6cab0bcc6f305a927218917040fd8f98039f0c Mon Sep 17 00:00:00 2001 From: Michael Landis Date: Thu, 27 Jun 2024 13:14:59 -0700 Subject: [PATCH] fix: use store_not_found metadata and appropriate exceptions Update the client to read `store_not_found` metadata to distinguish cache vs store not found. --- .../src/intTest/java/momento/sdk/storage/DataTests.java | 6 +++--- .../momento/sdk/exceptions/CacheServiceExceptionMapper.java | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/momento-sdk/src/intTest/java/momento/sdk/storage/DataTests.java b/momento-sdk/src/intTest/java/momento/sdk/storage/DataTests.java index 818ee18a..2a216804 100644 --- a/momento-sdk/src/intTest/java/momento/sdk/storage/DataTests.java +++ b/momento-sdk/src/intTest/java/momento/sdk/storage/DataTests.java @@ -7,7 +7,7 @@ import momento.sdk.PreviewStorageClient; import momento.sdk.auth.CredentialProvider; import momento.sdk.config.StorageConfigurations; -import momento.sdk.exceptions.CacheNotFoundException; +import momento.sdk.exceptions.StoreNotFoundException; import momento.sdk.responses.storage.DeleteResponse; import momento.sdk.responses.storage.GetResponse; import momento.sdk.responses.storage.PutResponse; @@ -112,11 +112,11 @@ public void badStoreNameReturnsError() { final GetResponse getResponse = client.get(storeName, "").join(); assertThat(getResponse).isInstanceOf(GetResponse.Error.class); - assertThat(((GetResponse.Error) getResponse)).hasCauseInstanceOf(CacheNotFoundException.class); + assertThat(((GetResponse.Error) getResponse)).hasCauseInstanceOf(StoreNotFoundException.class); final PutResponse putResponse = client.put(storeName, "", "").join(); assertThat(putResponse).isInstanceOf(PutResponse.Error.class); - assertThat(((PutResponse.Error) putResponse)).hasCauseInstanceOf(CacheNotFoundException.class); + assertThat(((PutResponse.Error) putResponse)).hasCauseInstanceOf(StoreNotFoundException.class); } @Test diff --git a/momento-sdk/src/main/java/momento/sdk/exceptions/CacheServiceExceptionMapper.java b/momento-sdk/src/main/java/momento/sdk/exceptions/CacheServiceExceptionMapper.java index 4dd9e69c..769ea4f4 100644 --- a/momento-sdk/src/main/java/momento/sdk/exceptions/CacheServiceExceptionMapper.java +++ b/momento-sdk/src/main/java/momento/sdk/exceptions/CacheServiceExceptionMapper.java @@ -83,7 +83,7 @@ public static SdkException convert(Throwable e, Metadata metadata) { case NOT_FOUND: if (errorCause.contains("item_not_found")) { return new StoreItemNotFoundException(grpcException, errorDetails); - } else if (errorCause.contains("Store with name")) { + } else if (errorCause.contains("store_not_found")) { return new StoreNotFoundException(grpcException, errorDetails); } else { return new CacheNotFoundException(grpcException, errorDetails);