Skip to content

Commit

Permalink
Add net8 global exception handler
Browse files Browse the repository at this point in the history
  • Loading branch information
aritchie committed Nov 26, 2023
1 parent e05c29e commit 13d0ac4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
20 changes: 20 additions & 0 deletions ProjectTemplates/ShinyAspNet/GlobalExceptionHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Microsoft.AspNetCore.Diagnostics;

namespace ShinyAspNet;


public class GlobalExceptionHandler : IExceptionHandler
{
readonly ILogger logger;

public GlobalExceptionHandler(ILogger<GlobalExceptionHandler> logger)
{
this.logger = logger;
}

public ValueTask<bool> TryHandleAsync(HttpContext httpContext, Exception exception, CancellationToken cancellationToken)
{
this.logger.LogError(exception, "Error processing request");
return ValueTask.FromResult(false);
}
}
2 changes: 2 additions & 0 deletions ProjectTemplates/ShinyAspNet/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
};
});

builder.Services.AddExceptionHandler<GlobalExceptionHandler>();

//#if (google)
builder.Services.AddAuthentication().AddGoogle(options =>
{
Expand Down

0 comments on commit 13d0ac4

Please sign in to comment.