修改异常处理

Test.EIImageViewer
hang 2023-06-14 10:23:36 +08:00
parent ed8791c9d7
commit 22df12f221
4 changed files with 32 additions and 8 deletions

View File

@ -35,8 +35,7 @@ namespace IRaCIS.Core.Application.Filter
}
else
{
context.Result = new JsonResult(ResponseOutput.NotOk(" 程序异常,请联系开发人员。 " + (context.Exception.InnerException is null ? (context.Exception.Message /*+ context.Exception.StackTrace*/)
: (context.Exception.InnerException?.Message /*+ context.Exception.InnerException?.StackTrace*/)), ApiResponseCodeEnum.ProgramException));
context.Result = new JsonResult(ResponseOutput.NotOk("当前操作失败,请联系开发人员查看系统日志排查 ", ApiResponseCodeEnum.ProgramException));
}

View File

@ -1,5 +1,6 @@
using DocumentFormat.OpenXml.Spreadsheet;
using IRaCIS.Core.Domain.Share;
using IRaCIS.Core.Infrastructure;
using MailKit;
using MailKit.Security;
using MimeKit;
@ -42,7 +43,7 @@ public static class SendEmailHelper
catch (Exception ex)
{
throw new Exception("邮件发送失败,您进行的操作未能成功,请检查邮箱或联系维护人员");
throw new BusinessValidationFailedException("邮件发送失败,您进行的操作未能成功,请检查邮箱或联系维护人员");
}
@ -62,7 +63,7 @@ public static class SendEmailHelper
if (sMTPEmailConfig.ToMailAddressList.Count == 0)
{
throw new ArgumentException("没有收件人");
throw new BusinessValidationFailedException("没有收件人");
}
else
{

View File

@ -8,6 +8,7 @@ using Panda.DynamicWebApi.Attributes;
using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.Options;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Logging;
namespace IRaCIS.Application.Services
{
@ -22,6 +23,8 @@ namespace IRaCIS.Application.Services
private readonly IMemoryCache _cache;
private ILogger<UserService> _logger;
private readonly IOptionsMonitor<ServiceVerifyConfigOption> _verifyConfig;
public UserService(IRepository<User> userRepository,
@ -30,10 +33,12 @@ namespace IRaCIS.Application.Services
IRepository<Doctor> doctorRepository,
IMemoryCache cache,
IRepository<TrialUser> userTrialRepository,
IOptionsMonitor<ServiceVerifyConfigOption> verifyConfig
IOptionsMonitor<ServiceVerifyConfigOption> verifyConfig,
ILogger<UserService> logger
)
{
_logger=logger;
_verifyConfig = verifyConfig;
_cache = cache;
_userRepository = userRepository;
@ -267,7 +272,7 @@ namespace IRaCIS.Application.Services
}
catch (Exception ex)
{
throw new BusinessValidationFailedException("请检查邮箱地址或者联系维护人员, 邮件发送失败, 未能创建账户成功");
throw new BusinessValidationFailedException("请检查邮箱地址或者联系维护人员, 邮件发送失败");
}
@ -506,9 +511,18 @@ namespace IRaCIS.Application.Services
var success = await _userRepository.SaveChangesAsync();
try
{
await _mailVerificationService.AddUserSendEmailAsync(saveItem.Id, userAddModel.BaseUrl, userAddModel.RouteUrl);
}
catch (Exception ex)
{
_logger.LogError(ex.Message);
throw new BusinessValidationFailedException("发送邮件失败, 未能创建账户成功");
}

View File

@ -535,7 +535,17 @@ namespace IRaCIS.Core.Infra.EFCore
throw new DBSaveFailedException("SQL 查询中存在语法错误。");
}
catch (ReferenceConstraintException ex)
{
_logger.LogError(ex.Message);
throw new DBSaveFailedException("无法进行当前操作,当前数据不符合外键约束。");
}
catch (DbUpdateConcurrencyException ex)
{
_logger.LogError(ex.Message);
throw new DBSaveFailedException("SQL 事务失败,请检查环境。");
}
return result;
}