From c94e48cea4ba955c4b3a829c67983a9890fc9843 Mon Sep 17 00:00:00 2001 From: gdlcf88 Date: Sun, 19 Mar 2023 19:18:16 +0800 Subject: [PATCH] Improve exception handling --- Directory.Build.props | 2 +- common.props | 2 +- .../Provider/Mailing/EmailNotificationManager.cs | 4 +++- .../Provider/Sms/SmsNotificationManager.cs | 4 +++- .../WeChatOfficialTemplateMessageNotificationManager.cs | 4 +++- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 3b74f61..588ca4e 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -3,7 +3,7 @@ 7.0.0 1.6.0 - 2.3.4 + 2.3.5 diff --git a/common.props b/common.props index 84491b1..ea09db7 100644 --- a/common.props +++ b/common.props @@ -1,7 +1,7 @@ latest - 2.0.0-preview.1 + 2.0.0-preview.2 $(NoWarn);CS1591 true EasyAbp Team diff --git a/providers/Mailing/EasyAbp.NotificationService.Provider.Mailing/EasyAbp/NotificationService/Provider/Mailing/EmailNotificationManager.cs b/providers/Mailing/EasyAbp.NotificationService.Provider.Mailing/EasyAbp/NotificationService/Provider/Mailing/EmailNotificationManager.cs index 56a0776..3ace05d 100644 --- a/providers/Mailing/EasyAbp.NotificationService.Provider.Mailing/EasyAbp/NotificationService/Provider/Mailing/EmailNotificationManager.cs +++ b/providers/Mailing/EasyAbp.NotificationService.Provider.Mailing/EasyAbp/NotificationService/Provider/Mailing/EmailNotificationManager.cs @@ -4,6 +4,7 @@ using EasyAbp.NotificationService.NotificationInfos; using EasyAbp.NotificationService.Notifications; using Microsoft.Extensions.Logging; +using Volo.Abp; using Volo.Abp.Emailing; using Volo.Abp.Uow; @@ -54,7 +55,8 @@ await EmailSender.SendAsync(userEmailAddress, catch (Exception e) { Logger.LogException(e); - await SetNotificationResultAsync(notification, false, e.ToString()); + var message = e is BusinessException b ? b.Code ?? b.Message : e.ToString(); + await SetNotificationResultAsync(notification, false, message); } } } \ No newline at end of file diff --git a/providers/Sms/EasyAbp.NotificationService.Provider.Sms/EasyAbp/NotificationService/Provider/Sms/SmsNotificationManager.cs b/providers/Sms/EasyAbp.NotificationService.Provider.Sms/EasyAbp/NotificationService/Provider/Sms/SmsNotificationManager.cs index a53b5bd..a301012 100644 --- a/providers/Sms/EasyAbp.NotificationService.Provider.Sms/EasyAbp/NotificationService/Provider/Sms/SmsNotificationManager.cs +++ b/providers/Sms/EasyAbp.NotificationService.Provider.Sms/EasyAbp/NotificationService/Provider/Sms/SmsNotificationManager.cs @@ -4,6 +4,7 @@ using EasyAbp.NotificationService.NotificationInfos; using EasyAbp.NotificationService.Notifications; using Microsoft.Extensions.Logging; +using Volo.Abp; using Volo.Abp.Json; using Volo.Abp.Sms; using Volo.Abp.Uow; @@ -65,7 +66,8 @@ await SetNotificationResultAsync(notification, false, catch (Exception e) { Logger.LogException(e); - await SetNotificationResultAsync(notification, false, e.ToString()); + var message = e is BusinessException b ? b.Code ?? b.Message : e.ToString(); + await SetNotificationResultAsync(notification, false, message); } } } \ No newline at end of file diff --git a/providers/WeChatOfficial/EasyAbp.NotificationService.Provider.WeChatOfficial/EasyAbp/NotificationService/Provider/WeChatOfficial/WeChatOfficialTemplateMessageNotificationManager.cs b/providers/WeChatOfficial/EasyAbp.NotificationService.Provider.WeChatOfficial/EasyAbp/NotificationService/Provider/WeChatOfficial/WeChatOfficialTemplateMessageNotificationManager.cs index b7b448c..934d15a 100644 --- a/providers/WeChatOfficial/EasyAbp.NotificationService.Provider.WeChatOfficial/EasyAbp/NotificationService/Provider/WeChatOfficial/WeChatOfficialTemplateMessageNotificationManager.cs +++ b/providers/WeChatOfficial/EasyAbp.NotificationService.Provider.WeChatOfficial/EasyAbp/NotificationService/Provider/WeChatOfficial/WeChatOfficialTemplateMessageNotificationManager.cs @@ -5,6 +5,7 @@ using EasyAbp.NotificationService.Notifications; using JetBrains.Annotations; using Microsoft.Extensions.Logging; +using Volo.Abp; using Volo.Abp.Uow; namespace EasyAbp.NotificationService.Provider.WeChatOfficial; @@ -76,7 +77,8 @@ await SetNotificationResultAsync(notification, false, catch (Exception e) { Logger.LogException(e); - await SetNotificationResultAsync(notification, false, e.ToString()); + var message = e is BusinessException b ? b.Code ?? b.Message : e.ToString(); + await SetNotificationResultAsync(notification, false, message); } }