Revert "add correct business exception handling"

This reverts commit b1693b2894.
This commit is contained in:
Alex Bezdieniezhnykh
2025-04-16 20:47:01 +03:00
parent b1693b2894
commit c1f47f0e8d
7 changed files with 12 additions and 45 deletions
+1 -7
View File
@@ -9,18 +9,12 @@
<ItemGroup>
<PackageReference Include="FluentValidation" Version="11.10.0" />
<PackageReference Include="linq2db" Version="5.4.1" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="9.0.4" />
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Npgsql" Version="8.0.5" />
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.AspNetCore.Diagnostics">
<HintPath>C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App\8.0.12\Microsoft.AspNetCore.Diagnostics.dll</HintPath>
</Reference>
<Reference Include="Microsoft.AspNetCore.Http.Abstractions">
<HintPath>C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App\8.0.12\Microsoft.AspNetCore.Http.Abstractions.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Extensions.Options">
<HintPath>C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App\8.0.8\Microsoft.Extensions.Options.dll</HintPath>
</Reference>
+1 -1
View File
@@ -12,7 +12,7 @@ public class BusinessException(ExceptionEnum exEnum) : Exception(GetMessage(exEn
ExceptionDescriptions = EnumExtensions.GetDescriptions<ExceptionEnum>();
}
public ExceptionEnum ExceptionEnum { get; set; } = exEnum;
private ExceptionEnum ExceptionEnum { get; set; } = exEnum;
public static string GetMessage(ExceptionEnum exEnum) => ExceptionDescriptions.GetValueOrDefault(exEnum) ?? exEnum.ToString();
}
-27
View File
@@ -1,27 +0,0 @@
using Microsoft.AspNetCore.Diagnostics;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
namespace Azaion.Common;
public class BusinessExceptionHandler(ILogger<BusinessExceptionHandler> logger) : IExceptionHandler
{
public async ValueTask<bool> TryHandleAsync(HttpContext httpContext, Exception exception, CancellationToken cancellationToken)
{
if (exception is not BusinessException ex)
return false;
logger.LogWarning(exception, ex.Message);
httpContext.Response.StatusCode = StatusCodes.Status409Conflict;
httpContext.Response.ContentType = "application/json";
var err = JsonConvert.SerializeObject(new
{
ErrorCode = ex.ExceptionEnum,
ex.Message
});
await httpContext.Response.WriteAsync(err, cancellationToken).ConfigureAwait(false);
return true;
}
}
-1
View File
@@ -3,7 +3,6 @@ using Azaion.Common.Configs;
using LinqToDB;
using Microsoft.Extensions.Options;
namespace Azaion.Common.Database;
public interface IDbFactory
+1 -1
View File
@@ -10,7 +10,7 @@ public class User
public UserConfig? UserConfig { get; set; } = null!;
public static string GetCacheKey(string? email) =>
public static string GetCacheKey(string email) =>
string.IsNullOrEmpty(email) ? "" : $"{nameof(User)}.{email}";
}