From 142ff36d3a70e23c68b66af342dbe34fa180453a Mon Sep 17 00:00:00 2001 From: sam Date: Sat, 23 Nov 2024 20:43:43 +0100 Subject: [PATCH] fix: stop crash on start with empty sentry dsn, make max avatar length a constant --- Foxnouns.Backend/Program.cs | 2 +- Foxnouns.Backend/Utils/ValidationUtils.cs | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Foxnouns.Backend/Program.cs b/Foxnouns.Backend/Program.cs index f0c3e19..17a56d9 100644 --- a/Foxnouns.Backend/Program.cs +++ b/Foxnouns.Backend/Program.cs @@ -18,7 +18,7 @@ builder.AddSerilog(); builder .WebHost.UseSentry(opts => { - opts.Dsn = config.Logging.SentryUrl; + opts.Dsn = config.Logging.SentryUrl ?? ""; opts.TracesSampleRate = config.Logging.SentryTracesSampleRate; opts.MaxRequestBodySize = RequestSize.Small; }) diff --git a/Foxnouns.Backend/Utils/ValidationUtils.cs b/Foxnouns.Backend/Utils/ValidationUtils.cs index 0969a47..bb225ff 100644 --- a/Foxnouns.Backend/Utils/ValidationUtils.cs +++ b/Foxnouns.Backend/Utils/ValidationUtils.cs @@ -162,6 +162,7 @@ public static partial class ValidationUtils } public const int MaxBioLength = 1024; + public const int MaxAvatarLength = 1_500_000; public static ValidationError? ValidateBio(string? bio) { @@ -183,7 +184,10 @@ public static partial class ValidationUtils return avatar?.Length switch { 0 => ValidationError.GenericValidationError("Avatar cannot be empty", null), - > 1_500_000 => ValidationError.GenericValidationError("Avatar is too large", null), + > MaxAvatarLength => ValidationError.GenericValidationError( + "Avatar is too large", + null + ), _ => null, }; }