Skip to content

Commit

Permalink
#10
Browse files Browse the repository at this point in the history
  • Loading branch information
vipwan committed Oct 15, 2023
1 parent 2545d32 commit 5813853
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Biwen.QuickApi.DemoWeb/CustomExceptionHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

namespace Biwen.QuickApi.DemoWeb
{
/// <summary>
/// 自定义异常处理
/// </summary>
public class CustomExceptionHandler : IQuickApiExceptionHandler
{
private readonly ILogger<CustomExceptionHandler> _logger;
public CustomExceptionHandler(ILogger<CustomExceptionHandler> logger)
{
_logger = logger;
}

public Task HandleAsync(Exception exception)
{
_logger.LogError(exception, "QuickApi异常");
return Task.CompletedTask;
}
}
}
3 changes: 3 additions & 0 deletions Biwen.QuickApi.DemoWeb/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@
//如果需要自定义异常返回格式
builder.Services.AddSingleton<IQuickApiExceptionResultBuilder, CustomExceptionResultBuilder>();

//自定义异常处理
builder.Services.AddScoped<IQuickApiExceptionHandler, CustomExceptionHandler>();


var app = builder.Build();

Expand Down

0 comments on commit 5813853

Please sign in to comment.