try catch and logging in hub
This commit is contained in:
parent
d21a0e176a
commit
769eabd9e4
31
NoteHub.cs
31
NoteHub.cs
@ -27,20 +27,29 @@ namespace BinaryDad.Notes
|
|||||||
|
|
||||||
public async Task SaveNote(string content, string noteName)
|
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
|
// find all other connections except for the current one
|
||||||
var clientConnections = NoteContext.ClientNotes
|
var clientConnections = NoteContext.ClientNotes
|
||||||
.Where(c => c.Value == noteName && c.Key != Context.ConnectionId)
|
.Where(c => c.Value == noteName && c.Key != Context.ConnectionId)
|
||||||
.Select(c => c.Key)
|
.Select(c => c.Key)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
// update note for all other clients
|
// update note for all other clients
|
||||||
await Clients
|
await Clients
|
||||||
.Clients(clientConnections)
|
.Clients(clientConnections)
|
||||||
.SendAsync("updateNote", content);
|
.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}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user