From 05b75bb2bac12f50476745ac19d7d2eef274de41 Mon Sep 17 00:00:00 2001 From: Erick Yondon <8766776+erdembayar@users.noreply.github.com> Date: Thu, 19 Sep 2024 09:32:08 -0700 Subject: [PATCH 1/5] Blob not found exception handle properly --- src/Catalog/Persistence/Storage.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Catalog/Persistence/Storage.cs b/src/Catalog/Persistence/Storage.cs index 69b59176b2..9287f022a1 100644 --- a/src/Catalog/Persistence/Storage.cs +++ b/src/Catalog/Persistence/Storage.cs @@ -8,6 +8,8 @@ using System.Net; using System.Threading; using System.Threading.Tasks; +using Azure; +using Azure.Storage.Blobs.Models; using Newtonsoft.Json; using NuGetGallery; @@ -125,6 +127,10 @@ public async Task DeleteAsync(Uri resourceUri, CancellationToken cancellationTok { await OnDeleteAsync(resourceUri, deleteRequestOptions, cancellationToken); } + catch (RequestFailedException ex) when (ex.ErrorCode == BlobErrorCode.BlobNotFound) + { + throw new CloudBlobNotFoundException(ex); + } catch (CloudBlobStorageException e) { WebException webException = e.InnerException as WebException; From 7946f9b857fae9d79816f19246110ed54014afcc Mon Sep 17 00:00:00 2001 From: Erick Yondon <8766776+erdembayar@users.noreply.github.com> Date: Thu, 19 Sep 2024 11:54:20 -0700 Subject: [PATCH 2/5] No need to rethrow --- src/Catalog/Persistence/Storage.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Catalog/Persistence/Storage.cs b/src/Catalog/Persistence/Storage.cs index 9287f022a1..b203ade8c9 100644 --- a/src/Catalog/Persistence/Storage.cs +++ b/src/Catalog/Persistence/Storage.cs @@ -129,7 +129,7 @@ public async Task DeleteAsync(Uri resourceUri, CancellationToken cancellationTok } catch (RequestFailedException ex) when (ex.ErrorCode == BlobErrorCode.BlobNotFound) { - throw new CloudBlobNotFoundException(ex); + // No need to rethrow, same as below statusCode != HttpStatusCode.NotFound for CloudBlobStorageException exception } catch (CloudBlobStorageException e) { From 5aaa526896e0cb97519954d4a6aa5eca2e0605d3 Mon Sep 17 00:00:00 2001 From: Erick Yondon <8766776+erdembayar@users.noreply.github.com> Date: Thu, 19 Sep 2024 11:58:11 -0700 Subject: [PATCH 3/5] Duplicate logic --- src/Catalog/Persistence/Storage.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Catalog/Persistence/Storage.cs b/src/Catalog/Persistence/Storage.cs index b203ade8c9..83cdb7f147 100644 --- a/src/Catalog/Persistence/Storage.cs +++ b/src/Catalog/Persistence/Storage.cs @@ -127,9 +127,21 @@ public async Task DeleteAsync(Uri resourceUri, CancellationToken cancellationTok { await OnDeleteAsync(resourceUri, deleteRequestOptions, cancellationToken); } - catch (RequestFailedException ex) when (ex.ErrorCode == BlobErrorCode.BlobNotFound) + catch (RequestFailedException ex) { - // No need to rethrow, same as below statusCode != HttpStatusCode.NotFound for CloudBlobStorageException exception + WebException webException = ex.InnerException as WebException; + if (webException != null) + { + HttpStatusCode statusCode = ((HttpWebResponse)webException.Response).StatusCode; + if (statusCode != HttpStatusCode.NotFound) + { + throw; + } + } + else + { + throw; + } } catch (CloudBlobStorageException e) { From ae3dedde8b536cf3079112195c17a939605e5282 Mon Sep 17 00:00:00 2001 From: Erick Yondon <8766776+erdembayar@users.noreply.github.com> Date: Thu, 19 Sep 2024 14:38:20 -0700 Subject: [PATCH 4/5] There's no inner exception --- src/Catalog/Persistence/Storage.cs | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/Catalog/Persistence/Storage.cs b/src/Catalog/Persistence/Storage.cs index 83cdb7f147..b68500c057 100644 --- a/src/Catalog/Persistence/Storage.cs +++ b/src/Catalog/Persistence/Storage.cs @@ -129,16 +129,7 @@ public async Task DeleteAsync(Uri resourceUri, CancellationToken cancellationTok } catch (RequestFailedException ex) { - WebException webException = ex.InnerException as WebException; - if (webException != null) - { - HttpStatusCode statusCode = ((HttpWebResponse)webException.Response).StatusCode; - if (statusCode != HttpStatusCode.NotFound) - { - throw; - } - } - else + if (ex.ErrorCode != BlobErrorCode.BlobNotFound) { throw; } From bcf3c2fe5cfec7b25b3007a643ab01715322eed8 Mon Sep 17 00:00:00 2001 From: Erick Yondon <8766776+erdembayar@users.noreply.github.com> Date: Thu, 19 Sep 2024 14:40:08 -0700 Subject: [PATCH 5/5] Better handling --- src/Catalog/Persistence/Storage.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Catalog/Persistence/Storage.cs b/src/Catalog/Persistence/Storage.cs index b68500c057..a34c99eab1 100644 --- a/src/Catalog/Persistence/Storage.cs +++ b/src/Catalog/Persistence/Storage.cs @@ -127,12 +127,9 @@ public async Task DeleteAsync(Uri resourceUri, CancellationToken cancellationTok { await OnDeleteAsync(resourceUri, deleteRequestOptions, cancellationToken); } - catch (RequestFailedException ex) + catch (RequestFailedException ex) when (ex.ErrorCode == BlobErrorCode.BlobNotFound) { - if (ex.ErrorCode != BlobErrorCode.BlobNotFound) - { - throw; - } + // Ignore this same as CloudBlobStorageException for below. } catch (CloudBlobStorageException e) {