refactor: Projektdateien migriert. Cloud-NuGet-Pakete durch lokale NuGet-Projekte ersetzt.
This commit is contained in:
39
HRD.WebApi/Helpers/ExceptionExtension.cs
Normal file
39
HRD.WebApi/Helpers/ExceptionExtension.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using HRD.AppLogger;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Diagnostics;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace HRD.WebApi.Helpers
|
||||
{
|
||||
public static class ExceptionExtension
|
||||
{
|
||||
public static void AddCustomExceptionHandling(this IApplicationBuilder app)
|
||||
{
|
||||
app.UseExceptionHandler(errorApp =>
|
||||
{
|
||||
errorApp.Run(async context =>
|
||||
{
|
||||
context.Response.StatusCode = StatusCodes.Status500InternalServerError;
|
||||
context.Response.ContentType = "application/json";
|
||||
var errorFeature = context.Features.Get<IExceptionHandlerFeature>();
|
||||
if (errorFeature != null)
|
||||
{
|
||||
HttpErrorDetails customError = new HttpErrorDetails
|
||||
{
|
||||
URI = context.Request.Path.ToUriComponent(),
|
||||
Status = context.Response.StatusCode,
|
||||
Detail = errorFeature.Error.Message
|
||||
};
|
||||
|
||||
ILoggerManager logger = new LoggerManager();
|
||||
logger.LogException(errorFeature.Error, null, customError.URI);
|
||||
|
||||
await context.Response.WriteAsync(customError.ToJsonString()).ConfigureAwait(false);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user