From 054f4989eabcff4bd0cbcb0a649ea6bd8044df6b Mon Sep 17 00:00:00 2001 From: "Collin M. Barrett" Date: Wed, 15 Aug 2018 19:44:14 -0500 Subject: [PATCH] EnsureHttpStatusCodeSaved() ref #343 --- src/FilterLists.Services/Snapshot/SnapshotDe.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/FilterLists.Services/Snapshot/SnapshotDe.cs b/src/FilterLists.Services/Snapshot/SnapshotDe.cs index b1cb6fb94..6ad39bf08 100644 --- a/src/FilterLists.Services/Snapshot/SnapshotDe.cs +++ b/src/FilterLists.Services/Snapshot/SnapshotDe.cs @@ -22,6 +22,7 @@ public class SnapshotDe private readonly EmailService emailService; private readonly FilterListViewUrlDto list; private readonly Data.Entities.Snapshot snapshot; + private string httpStatusCodeBak; public SnapshotDe(FilterListsDbContext dbContext, EmailService emailService, FilterListViewUrlDto list) { @@ -57,6 +58,8 @@ public async Task SaveAsync() await SendExceptionEmail(e); } } + + await EnsureHttpStatusCodeSaved(); } private async Task AddSnapshot() @@ -93,6 +96,7 @@ private async Task GetContent() using (var httpResponseMessage = await httpClient.GetAsync(list.ViewUrl)) { snapshot.HttpStatusCode = ((int)httpResponseMessage.StatusCode).ToString(); + httpStatusCodeBak = snapshot.HttpStatusCode; if (httpResponseMessage.IsSuccessStatusCode) return await httpResponseMessage.Content.ReadAsStringAsync(); } @@ -102,6 +106,15 @@ private async Task GetContent() return null; } + private async Task EnsureHttpStatusCodeSaved() + { + if (!snapshot.WasSuccessful) + { + snapshot.HttpStatusCode = httpStatusCodeBak; + await dbContext.SaveChangesAsync(); + } + } + private async Task SendWebExceptionEmail() { var message = new StringBuilder();