Code: Select all
public void ConfigureServices( IServiceCollection services )
{
services.AddMvc(options => options.Filters.Add(typeof(ExceptionFilter)));
// ...
}
if (GetUseErrorEmailVar())
{
app.UseExceptionHandler(appException =>
{
appException.Run(async context =>
{
var exceptionFeature = context.Features.Get();
if ( exceptionFeature?.Error is FileNotFoundException )
{
await context.Response.WriteAsync(" The file was not found.");
}
if (exceptionFeature?.Path == "/")
{
await context.Response.WriteAsync(" Page: Home.");
}
if (exceptionFeature.Error is ApiErrorException exception)
{
await context.Response.WriteAsync(JsonConvert.SerializeObject(new BaseReturnDataObject
{
ErrorType = exception.GetType().ToString(),
ErrorMsg = exception.Message
}
)
);
}
////else if (exceptionFeature.Error is ApiLoginErrorException exception2)
////{
//// // Debug instead of error, because SMTP appender makes a duplicate email (actually 3) - EWB
//// log.LogDebug("Startup::Configure(...):: Global exception handler ; LOGIN ex:" + exceptionFeature.Error.ToStringNullSafe());
////}
////else// everything else -EWB
////{
//// // Debug instead of error, because SMTP appender makes a duplicate email (actually 3) - EWB
//// log.LogDebug("Startup::Configure(...):: Global exception handler ; ERROR ex:"+ exceptionFeature.Error.ToStringNullSafe());
////
//// exceptionFeature.Error.Data["handled"] = true;
////}
});
});
}
app.UseElmah();// must be after all other handlers and middleware for errors. -EWB
< /code>
Aber weder dieser Ausnahme -Handler Lambda noch mein explizite Ausnahmebehandler werden aufgerufen, sodass ich entscheiden kann, ob es die Nachricht unterdrückt oder nicht, wenn es sich um 404 handelt. Wie Sachen, von denen ich noch nie gehört habe ... Ich gehe davon aus, dass sie von späteren Versionen der Web -API stammen. Ich bin auf .net 6.