From 78e0f6d9f4deb66e40245606492dec19a23cd60f Mon Sep 17 00:00:00 2001 From: Luciana Regina Lino Date: Wed, 7 Feb 2024 18:44:27 -0300 Subject: [PATCH] feat(BlobStorageAdapter.cs): supress error "BlobNotFound" and return null instead. --- .../BlobStorageAdapter.cs | 35 +++++++++++++------ .../Liquid.Adapter.AzureStorage.csproj | 2 +- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/Liquid.Adapter.AzureStorage/BlobStorageAdapter.cs b/src/Liquid.Adapter.AzureStorage/BlobStorageAdapter.cs index 3673a80..dfff14b 100644 --- a/src/Liquid.Adapter.AzureStorage/BlobStorageAdapter.cs +++ b/src/Liquid.Adapter.AzureStorage/BlobStorageAdapter.cs @@ -1,4 +1,5 @@ -using Azure.Storage.Blobs.Models; +using Azure; +using Azure.Storage.Blobs.Models; using Azure.Storage.Blobs.Specialized; using Azure.Storage.Sas; using System.Diagnostics.CodeAnalysis; @@ -129,19 +130,31 @@ public async Task UploadBlob(byte[] data, string name, string containerN /// public async Task ReadBlobsByName(string blobName, string containerName) { - var client = _factory.GetContainerClient(containerName); + try + { + var client = _factory.GetContainerClient(containerName); + var blockBlob = client.GetBlockBlobClient(blobName); + var blob = await blockBlob.DownloadContentAsync(); + var item = new LiquidBlob + { + Blob = blob.Value.Content.ToArray(), + Tags = blockBlob.GetTags().Value.Tags, + Name = blobName, + AbsoluteUri = blockBlob.Uri.AbsoluteUri + }; - var blockBlob = client.GetBlockBlobClient(blobName); - var blob = await blockBlob.DownloadContentAsync(); - var item = new LiquidBlob + return item; + } + catch (RequestFailedException storageRequestFailedException) + when (storageRequestFailedException.ErrorCode == BlobErrorCode.BlobNotFound) { - Blob = blob.Value.Content.ToArray(), - Tags = blockBlob.GetTags().Value.Tags, - Name = blobName, - AbsoluteUri = blockBlob.Uri.AbsoluteUri - }; + return null; + } + catch (Exception) + { + throw; + } - return item; } /// diff --git a/src/Liquid.Adapter.AzureStorage/Liquid.Adapter.AzureStorage.csproj b/src/Liquid.Adapter.AzureStorage/Liquid.Adapter.AzureStorage.csproj index f4cf27c..5132113 100644 --- a/src/Liquid.Adapter.AzureStorage/Liquid.Adapter.AzureStorage.csproj +++ b/src/Liquid.Adapter.AzureStorage/Liquid.Adapter.AzureStorage.csproj @@ -8,7 +8,7 @@ Avanade Inc. Liquid - Modern Application Framework Avanade 2019 - 6.0.0-preview-20221201-03 + 6.0.0-preview-20221201-04 true true