From 99a3f2614d60ff9c2c0cc5868be76c1d1f1d9c89 Mon Sep 17 00:00:00 2001 From: Glax Date: Tue, 1 Apr 2025 18:24:25 +0200 Subject: [PATCH] Catch Stream closed --- API/MangaDownloadClients/DownloadClient.cs | 4 +++- API/MangaDownloadClients/HttpDownloadClient.cs | 13 +++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/API/MangaDownloadClients/DownloadClient.cs b/API/MangaDownloadClients/DownloadClient.cs index d930852..c611a33 100644 --- a/API/MangaDownloadClients/DownloadClient.cs +++ b/API/MangaDownloadClients/DownloadClient.cs @@ -1,14 +1,16 @@ using System.Net; -using API.Schema; +using log4net; namespace API.MangaDownloadClients; internal abstract class DownloadClient { private readonly Dictionary _lastExecutedRateLimit; + protected ILog Log { get; init; } protected DownloadClient() { + this.Log = LogManager.GetLogger(GetType()); this._lastExecutedRateLimit = new(); } diff --git a/API/MangaDownloadClients/HttpDownloadClient.cs b/API/MangaDownloadClients/HttpDownloadClient.cs index 332cfab..b72b29b 100644 --- a/API/MangaDownloadClients/HttpDownloadClient.cs +++ b/API/MangaDownloadClients/HttpDownloadClient.cs @@ -48,8 +48,17 @@ internal class HttpDownloadClient : DownloadClient { return new RequestResult(response.StatusCode, null, Stream.Null); } - - Stream stream = response.Content.ReadAsStream(); + + Stream stream; + try + { + stream = response.Content.ReadAsStream(); + } + catch (Exception e) + { + Log.Error(e); + return new RequestResult(HttpStatusCode.InternalServerError, null, Stream.Null); + } HtmlDocument? document = null;