Skip to content

Usenet streaming with a WebDAV server and a SABnzbd-compatible API

C#

Provide less intrusive logging for seek-position errors.

nzbdav-devae93d0cc9aca
diff --git a/backend/Exceptions/SeekPositionNotFoundException.cs b/backend/Exceptions/SeekPositionNotFoundException.cs
new file mode 100644
index 00000000..4f8abac9
--- /dev/null
+++ b/backend/Exceptions/SeekPositionNotFoundException.cs
@@ -0,0 +1,5 @@
+namespace NzbWebDAV.Exceptions;
+
+public class SeekPositionNotFoundException(string message) : NonRetryableDownloadException(message)
+{
+}
\ No newline at end of file
diff --git a/backend/Middlewares/ExceptionMiddleware.cs b/backend/Middlewares/ExceptionMiddleware.cs
index 34cd7a9f..1939f2a0 100644
--- a/backend/Middlewares/ExceptionMiddleware.cs
+++ b/backend/Middlewares/ExceptionMiddleware.cs
@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Http;
+using NWebDav.Server.Helpers;
using NzbWebDAV.Exceptions;
using Serilog;
@@ -32,5 +33,16 @@ public class ExceptionMiddleware(RequestDelegate next)
Log.Warning($"File `{context.Request.Path}` has missing articles: {e.Message}");
}
+ catch (SeekPositionNotFoundException)
+ {
+ if (!context.Response.HasStarted)
+ {
+ context.Response.Clear();
+ context.Response.StatusCode = 404;
+ }
+
+ var seekPosition = context.Request.GetRange()?.Start?.ToString() ?? "unknown";
+ Log.Warning($"File `{context.Request.Path}` could not seek to byte position: {seekPosition}");
+ }
}
}
\ No newline at end of file
diff --git a/backend/Utils/InterpolationSearch.cs b/backend/Utils/InterpolationSearch.cs
index 3caa5208..99f70024 100644
--- a/backend/Utils/InterpolationSearch.cs
+++ b/backend/Utils/InterpolationSearch.cs
@@ -1,4 +1,6 @@
-namespace NzbWebDAV.Utils;
+using NzbWebDAV.Exceptions;
+
+namespace NzbWebDAV.Utils;
public static class InterpolationSearch
{
@@ -17,7 +19,7 @@ public static class InterpolationSearch
// make sure our search is even possible.
if (!byteRangeToSearch.Contains(searchByte) || indexRangeToSearch.Count <= 0)
- throw new Exception($"Corrupt file. Cannot find byte position {searchByte}.");
+ throw new SeekPositionNotFoundException($"Corrupt file. Cannot find byte position {searchByte}.");
// make a guess
var searchByteFromStart = searchByte - byteRangeToSearch.StartInclusive;
@@ -28,7 +30,7 @@ public static class InterpolationSearch
// make sure the result is within the range of our search space
if (!byteRangeOfGuessedIndex.IsContainedWithin(byteRangeToSearch))
- throw new Exception($"Corrupt file. Cannot find byte position {searchByte}.");
+ throw new SeekPositionNotFoundException($"Corrupt file. Cannot find byte position {searchByte}.");
// if we guessed too low, adjust our lower bounds in order to search higher next time
if (byteRangeOfGuessedIndex.EndExclusive <= searchByte)