File tree Expand file tree Collapse file tree 2 files changed +14
-2
lines changed
Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change 11using Microsoft . AspNetCore . Http ;
2+ using NzbWebDAV . Exceptions ;
3+ using Serilog ;
24
35namespace 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}
Original file line number Diff line number Diff 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 ( ) ;
You can’t perform that action at this time.
0 commit comments