Kavita is a fast, feature rich, cross platform reading server. Built with the goal of being a full solution for all your reading needs. Setup your own server and share your reading collection with your friends and family.
C# annotationscbzcomicinfocomicscomics-readercross-platformcsharpepubepub-readerfreelinuxmangamedia-servermetadataopdsopds-feedpdfself-hostedubooquitywindows
Tell sentry to ignore some noisy messages, add a bounds check on an API, and tweak some ERRORs to be WARNINGs to better reflect their severity. (#216)
Joseph Milazzo98e8b7297b22
diff --git a/API/Controllers/ReaderController.cs b/API/Controllers/ReaderController.csindex 8e8c8c27e..0436e7d65 100644--- a/API/Controllers/ReaderController.cs+++ b/API/Controllers/ReaderController.cs@@ -32,6 +32,7 @@ namespace API.Controllers[HttpGet("image")]public async Task<ActionResult> GetImage(int chapterId, int page){+ if (page < 0) return BadRequest("Page cannot be less than 0");var chapter = await _cacheService.Ensure(chapterId);if (chapter == null) return BadRequest("There was an issue finding image file for reading");diff --git a/API/Program.cs b/API/Program.csindex c8dc9d1b2..2240e6ad6 100644--- a/API/Program.cs+++ b/API/Program.cs@@ -14,6 +14,7 @@ using Microsoft.Extensions.DependencyInjection;using Microsoft.Extensions.Hosting;using Microsoft.Extensions.Logging;using Sentry;+using Sentry.Extensions.Logging;namespace API{@@ -24,10 +25,12 @@ namespace APIprotected Program(){}-+public static async Task Main(string[] args){// Before anything, check if JWT has been generated properly or if user still has default++var host = CreateHostBuilder(args).Build();@@ -45,7 +48,7 @@ namespace API}catch (Exception ex){- var logger = services.GetRequiredService < ILogger<Program>>();+ var logger = services.GetRequiredService <ILogger<Program>>();logger.LogError(ex, "An error occurred during migration");}@@ -77,6 +80,19 @@ namespace APIoptions.AddExceptionFilterForType<OutOfMemoryException>();options.AddExceptionFilterForType<NetVips.VipsException>();options.AddExceptionFilterForType<InvalidDataException>();++ options.BeforeSend = sentryEvent =>+ {+ if (sentryEvent.Exception != null+ && sentryEvent.Exception.Message.Contains("[GetCoverImage] This archive cannot be read:"))+ {+ return null; // Don't send this event to Sentry+ }++ sentryEvent.ServerName = null; // Never send Server Name to Sentry+ return sentryEvent;+ };+options.ConfigureScope(scope =>{scope.User = new User()diff --git a/API/Services/ArchiveService.cs b/API/Services/ArchiveService.csindex dc490844c..b3ef35ee9 100644--- a/API/Services/ArchiveService.cs+++ b/API/Services/ArchiveService.cs@@ -91,16 +91,16 @@ namespace API.Services&& Parser.Parser.IsImage(entry.Key));}case ArchiveLibrary.NotSupported:- _logger.LogError("[GetNumberOfPagesFromArchive] This archive cannot be read: {ArchivePath}. Defaulting to 0 pages", archivePath);+ _logger.LogWarning("[GetNumberOfPagesFromArchive] This archive cannot be read: {ArchivePath}. Defaulting to 0 pages", archivePath);return 0;default:- _logger.LogError("[GetNumberOfPagesFromArchive] There was an exception when reading archive stream: {ArchivePath}. Defaulting to 0 pages", archivePath);+ _logger.LogWarning("[GetNumberOfPagesFromArchive] There was an exception when reading archive stream: {ArchivePath}. Defaulting to 0 pages", archivePath);return 0;}}catch (Exception ex){- _logger.LogError(ex, "[GetNumberOfPagesFromArchive] There was an exception when reading archive stream: {ArchivePath}. Defaulting to 0 pages", archivePath);+ _logger.LogWarning(ex, "[GetNumberOfPagesFromArchive] There was an exception when reading archive stream: {ArchivePath}. Defaulting to 0 pages", archivePath);return 0;}}@@ -180,16 +180,16 @@ namespace API.Servicesreturn createThumbnail ? CreateThumbnail(entry.Key, ms, Path.GetExtension(entry.Key)) : ms.ToArray();}case ArchiveLibrary.NotSupported:- _logger.LogError("[GetCoverImage] This archive cannot be read: {ArchivePath}. Defaulting to no cover image", archivePath);+ _logger.LogWarning("[GetCoverImage] This archive cannot be read: {ArchivePath}. Defaulting to no cover image", archivePath);return Array.Empty<byte>();default:- _logger.LogError("[GetCoverImage] There was an exception when reading archive stream: {ArchivePath}. Defaulting to no cover image", archivePath);+ _logger.LogWarning("[GetCoverImage] There was an exception when reading archive stream: {ArchivePath}. Defaulting to no cover image", archivePath);return Array.Empty<byte>();}}catch (Exception ex){- _logger.LogError(ex, "[GetCoverImage] There was an exception when reading archive stream: {ArchivePath}. Defaulting to no cover image", archivePath);+ _logger.LogWarning(ex, "[GetCoverImage] There was an exception when reading archive stream: {ArchivePath}. Defaulting to no cover image", archivePath);}return Array.Empty<byte>();@@ -230,7 +230,7 @@ namespace API.Services}catch (Exception ex){- _logger.LogError(ex, "There was a critical error and prevented thumbnail generation on {EntryName}. Defaulting to no cover image", entryName);+ _logger.LogWarning(ex, "There was an error and prevented thumbnail generation on {EntryName}. Defaulting to no cover image", entryName);}return Array.Empty<byte>();@@ -313,10 +313,10 @@ namespace API.Servicesbreak;}case ArchiveLibrary.NotSupported:- _logger.LogError("[GetSummaryInfo] This archive cannot be read: {ArchivePath}", archivePath);+ _logger.LogWarning("[GetSummaryInfo] This archive cannot be read: {ArchivePath}", archivePath);return summary;default:- _logger.LogError("[GetSummaryInfo] There was an exception when reading archive stream: {ArchivePath}", archivePath);+ _logger.LogWarning("[GetSummaryInfo] There was an exception when reading archive stream: {ArchivePath}", archivePath);return summary;}@@ -327,7 +327,7 @@ namespace API.Services}catch (Exception ex){- _logger.LogError(ex, "[GetSummaryInfo] There was an exception when reading archive stream: {Filepath}", archivePath);+ _logger.LogWarning(ex, "[GetSummaryInfo] There was an exception when reading archive stream: {Filepath}", archivePath);}return summary;@@ -397,17 +397,17 @@ namespace API.Servicesbreak;}case ArchiveLibrary.NotSupported:- _logger.LogError("[ExtractArchive] This archive cannot be read: {ArchivePath}. Defaulting to 0 pages", archivePath);+ _logger.LogWarning("[ExtractArchive] This archive cannot be read: {ArchivePath}. Defaulting to 0 pages", archivePath);return;default:- _logger.LogError("[ExtractArchive] There was an exception when reading archive stream: {ArchivePath}. Defaulting to 0 pages", archivePath);+ _logger.LogWarning("[ExtractArchive] There was an exception when reading archive stream: {ArchivePath}. Defaulting to 0 pages", archivePath);return;}}catch (Exception e){- _logger.LogError(e, "There was a problem extracting {ArchivePath} to {ExtractPath}",archivePath, extractPath);+ _logger.LogWarning(e, "There was a problem extracting {ArchivePath} to {ExtractPath}",archivePath, extractPath);return;}_logger.LogDebug("Extracted archive to {ExtractPath} in {ElapsedMilliseconds} milliseconds", extractPath, sw.ElapsedMilliseconds);diff --git a/API/Startup.cs b/API/Startup.csindex f030fda92..90c796944 100644--- a/API/Startup.cs+++ b/API/Startup.cs@@ -1,4 +1,5 @@using System;+using System.IO;using System.IO.Compression;using System.Linq;using System.Reflection;@@ -147,5 +148,7 @@ namespace APISystem.Threading.Thread.Sleep(1000);Console.WriteLine("You may now close the application window.");}++}}diff --git a/Kavita.Common/Configuration.cs b/Kavita.Common/Configuration.csnew file mode 100644index 000000000..e69de29bb