Skip to content

Commit 2f4f523

Browse files
committed
Add less intrusive logging for missing articles.
1 parent 393b2a8 commit 2f4f523

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

backend/Middlewares/RequestCancelledMiddleware.cs renamed to backend/Middlewares/ExceptionMiddleware.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
using Microsoft.AspNetCore.Http;
2+
using NzbWebDAV.Exceptions;
3+
using Serilog;
24

35
namespace NzbWebDAV.Middlewares;
46

5-
public class RequestCancelledMiddleware(RequestDelegate next)
7+
public class ExceptionMiddleware(RequestDelegate next)
68
{
79
public async Task InvokeAsync(HttpContext context)
810
{
@@ -20,5 +22,15 @@ public async Task InvokeAsync(HttpContext context)
2022
await context.Response.WriteAsync("Client closed request.");
2123
}
2224
}
25+
catch (UsenetArticleNotFoundException e)
26+
{
27+
if (!context.Response.HasStarted)
28+
{
29+
context.Response.Clear();
30+
context.Response.StatusCode = 404;
31+
}
32+
33+
Log.Warning($"File `{context.Request.Path}` has missing articles: {e.Message}");
34+
}
2335
}
2436
}

backend/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ static async Task Main(string[] args)
8686
// run
8787
var app = builder.Build();
8888
app.UseSerilogRequestLogging();
89-
app.UseMiddleware<RequestCancelledMiddleware>();
89+
app.UseMiddleware<ExceptionMiddleware>();
9090
app.UseAuthentication();
9191
app.MapControllers();
9292
app.UseNWebDav();

0 commit comments

Comments
 (0)