From 88779e71297060053af2bc48e3aa9e71c0382f4a Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Fri, 12 Jan 2018 18:32:46 +0900 Subject: [PATCH] Make sure websockets does not throw, fix annying warning of emails --- BTCPayServer/Controllers/InvoiceController.UI.cs | 4 ++-- BTCPayServer/Services/Mails/EmailSender.cs | 14 +++++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/BTCPayServer/Controllers/InvoiceController.UI.cs b/BTCPayServer/Controllers/InvoiceController.UI.cs index 96873d157..433908942 100644 --- a/BTCPayServer/Controllers/InvoiceController.UI.cs +++ b/BTCPayServer/Controllers/InvoiceController.UI.cs @@ -262,7 +262,7 @@ namespace BTCPayServer.Controllers { await webSocket.SendAsync(DummyBuffer, WebSocketMessageType.Binary, true, cts.Token); } - catch { await CloseSocket(webSocket); } + catch { try { webSocket.Dispose(); } catch { } } } private static async Task CloseSocket(WebSocket webSocket) @@ -277,7 +277,7 @@ namespace BTCPayServer.Controllers } } catch { } - finally { webSocket.Dispose(); } + finally { try { webSocket.Dispose(); } catch { } } } [HttpPost] diff --git a/BTCPayServer/Services/Mails/EmailSender.cs b/BTCPayServer/Services/Mails/EmailSender.cs index c663cdd3b..c97c2cbbd 100644 --- a/BTCPayServer/Services/Mails/EmailSender.cs +++ b/BTCPayServer/Services/Mails/EmailSender.cs @@ -1,4 +1,6 @@ -using Hangfire; +using BTCPayServer.Logging; +using Microsoft.Extensions.Logging; +using Hangfire; using System; using System.Collections.Generic; using System.Linq; @@ -20,10 +22,16 @@ namespace BTCPayServer.Services.Mails _JobClient = jobClient; _Repository = repository; } - public Task SendEmailAsync(string email, string subject, string message) + public async Task SendEmailAsync(string email, string subject, string message) { + var settings = await _Repository.GetSettingAsync(); + if (settings == null) + { + Logs.Configuration.LogWarning("Should have sent email, but email settings are not configured"); + return; + } _JobClient.Schedule(() => SendMailCore(email, subject, message), TimeSpan.Zero); - return Task.CompletedTask; + return; } public async Task SendMailCore(string email, string subject, string message)