From 769eabd9e4b86e6ac72af979c1d6919f37d886e6 Mon Sep 17 00:00:00 2001 From: Ryan Peters Date: Mon, 16 Dec 2024 16:10:17 -0500 Subject: [PATCH] try catch and logging in hub --- NoteHub.cs | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/NoteHub.cs b/NoteHub.cs index 5aff2f7..80b5e8b 100644 --- a/NoteHub.cs +++ b/NoteHub.cs @@ -27,20 +27,29 @@ namespace BinaryDad.Notes public async Task SaveNote(string content, string noteName) { - logger.LogInformation($"Saving note \"{noteName}\""); + try + { + logger.LogInformation($"Saving note \"{noteName}\""); - noteService.SaveNote(content, noteName); + noteService.SaveNote(content, noteName); - // find all other connections except for the current one - var clientConnections = NoteContext.ClientNotes - .Where(c => c.Value == noteName && c.Key != Context.ConnectionId) - .Select(c => c.Key) - .ToList(); + // find all other connections except for the current one + var clientConnections = NoteContext.ClientNotes + .Where(c => c.Value == noteName && c.Key != Context.ConnectionId) + .Select(c => c.Key) + .ToList(); - // update note for all other clients - await Clients - .Clients(clientConnections) - .SendAsync("updateNote", content); + // update note for all other clients + await Clients + .Clients(clientConnections) + .SendAsync("updateNote", content); + + logger.LogInformation($"NOTE \"{noteName}\" SAVED! Updated {clientConnections.Count} other client(s)."); + } + catch (Exception ex) + { + logger.LogError($"Unable to save note \"{noteName}\" => {ex}"); + } } } }