From f8ddac9c523c18eb4662191d66b2b7ddc43bc863 Mon Sep 17 00:00:00 2001 From: Ahmet Alp Balkan Date: Thu, 28 Jun 2018 21:46:48 -0700 Subject: [PATCH] cartservice: add try catch to GetCartAsync Signed-off-by: Ahmet Alp Balkan --- src/cartservice/cartstore/RedisCartStore.cs | 23 ++++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/cartservice/cartstore/RedisCartStore.cs b/src/cartservice/cartstore/RedisCartStore.cs index 50f1f6f..ddf73dd 100644 --- a/src/cartservice/cartstore/RedisCartStore.cs +++ b/src/cartservice/cartstore/RedisCartStore.cs @@ -81,18 +81,25 @@ namespace cartservice.cartstore public async Task GetCartAsync(string userId) { Console.WriteLine($"GetCartAsync called with userId={userId}"); - var db = redis.GetDatabase(); - - // Access the cart from the cache - var value = await db.HashGetAsync(userId, CART_FIELD_NAME); - - if (!value.IsNull) + try { - return Hipstershop.Cart.Parser.ParseFrom(value); + var db = redis.GetDatabase(); + + // Access the cart from the cache + var value = await db.HashGetAsync(userId, CART_FIELD_NAME); + + if (!value.IsNull) + { + return Hipstershop.Cart.Parser.ParseFrom(value); + } + } + catch (Exception e) + { + Console.WriteLine(e); } // We decided to return empty cart in cases when user wasn't in the cache before return new Hipstershop.Cart(); } } -} \ No newline at end of file +}