diff --git a/API/Extensions/ClaimsPrincipalExtensions.cs b/API/Extensions/ClaimsPrincipalExtensions.cs index 3dacfc854..61ece5676 100644 --- a/API/Extensions/ClaimsPrincipalExtensions.cs +++ b/API/Extensions/ClaimsPrincipalExtensions.cs @@ -1,4 +1,5 @@ using System.Security.Claims; +using Kavita.Common; namespace API.Extensions { @@ -6,7 +7,9 @@ namespace API.Extensions { public static string GetUsername(this ClaimsPrincipal user) { - return user.FindFirst(ClaimTypes.NameIdentifier)?.Value; + var userClaim = user.FindFirst(ClaimTypes.NameIdentifier); + if (userClaim == null) throw new KavitaException("User is not authenticated"); + return userClaim.Value; } } } \ No newline at end of file diff --git a/API/Program.cs b/API/Program.cs index 3bee9e202..4ea8f4e40 100644 --- a/API/Program.cs +++ b/API/Program.cs @@ -99,6 +99,7 @@ namespace API options.AddExceptionFilterForType(); options.AddExceptionFilterForType(); options.AddExceptionFilterForType(); + options.AddExceptionFilterForType(); options.BeforeSend = sentryEvent => { diff --git a/Kavita.Common/KavitaException.cs b/Kavita.Common/KavitaException.cs new file mode 100644 index 000000000..e91525f7e --- /dev/null +++ b/Kavita.Common/KavitaException.cs @@ -0,0 +1,21 @@ +using System; + +namespace Kavita.Common +{ + /// + /// These are used for errors to send to the UI that should not be reported to Sentry + /// + [Serializable] + public class KavitaException : Exception + { + public KavitaException() + { + + } + + public KavitaException(string message) : base(message) + { + + } + } +} \ No newline at end of file diff --git a/README.md b/README.md index 6e938811c..48f975d55 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ your reading collection with your friends and family! ## How to install - Unzip the archive for your target OS - Place in a directory that is writable. If on windows, do not place in Program Files +- Linux users must ensure the directory & kavita.db is writable by Kavita (might require starting server once) - Run Kavita - If you are updating, do not copy appsettings.json from the new version over. It will override your TokenKey and you will have to reauthenticate on your devices.