From 4af69a6afa0c5ce2445e4a1a0ba53da58bee900b Mon Sep 17 00:00:00 2001
From: Laura Hausmann
Date: Sat, 16 Nov 2024 22:45:06 +0100
Subject: [PATCH] [backend/asp] Add ExceptionVerbosity level Debug
---
.../Core/Middleware/ErrorHandlerMiddleware.cs | 11 +++----
.../Pages/Shared/ErrorPage.cshtml | 29 +++++++++++--------
Iceshrimp.Backend/configuration.ini | 6 +++-
3 files changed, 28 insertions(+), 18 deletions(-)
diff --git a/Iceshrimp.Backend/Core/Middleware/ErrorHandlerMiddleware.cs b/Iceshrimp.Backend/Core/Middleware/ErrorHandlerMiddleware.cs
index 8845c372..22b3c6a0 100644
--- a/Iceshrimp.Backend/Core/Middleware/ErrorHandlerMiddleware.cs
+++ b/Iceshrimp.Backend/Core/Middleware/ErrorHandlerMiddleware.cs
@@ -97,9 +97,9 @@ public class ErrorHandlerMiddleware(
StatusCode = ctx.Response.StatusCode,
Error = verbosity >= ExceptionVerbosity.Basic ? ce.Error : ce.StatusCode.ToString(),
Message = verbosity >= ExceptionVerbosity.Basic ? ce.Message : null,
- Details = verbosity == ExceptionVerbosity.Full ? ce.Details : null,
- Errors = verbosity == ExceptionVerbosity.Full ? (ce as ValidationException)?.Errors : null,
- Source = verbosity == ExceptionVerbosity.Full ? type : null,
+ Details = verbosity >= ExceptionVerbosity.Full ? ce.Details : null,
+ Errors = verbosity >= ExceptionVerbosity.Full ? (ce as ValidationException)?.Errors : null,
+ Source = verbosity >= ExceptionVerbosity.Full ? type : null,
RequestId = ctx.TraceIdentifier
};
@@ -125,7 +125,7 @@ public class ErrorHandlerMiddleware(
StatusCode = 500,
Error = "Internal Server Error",
Message = verbosity >= ExceptionVerbosity.Basic ? e.Message : null,
- Source = verbosity == ExceptionVerbosity.Full ? type : null,
+ Source = verbosity >= ExceptionVerbosity.Full ? type : null,
RequestId = ctx.TraceIdentifier
};
@@ -294,5 +294,6 @@ public enum ExceptionVerbosity
[SuppressMessage("ReSharper", "UnusedMember.Global")]
None = 0,
Basic = 1,
- Full = 2
+ Full = 2,
+ Debug = 3,
}
\ No newline at end of file
diff --git a/Iceshrimp.Backend/Pages/Shared/ErrorPage.cshtml b/Iceshrimp.Backend/Pages/Shared/ErrorPage.cshtml
index fda8a1e5..8113c44b 100644
--- a/Iceshrimp.Backend/Pages/Shared/ErrorPage.cshtml
+++ b/Iceshrimp.Backend/Pages/Shared/ErrorPage.cshtml
@@ -5,6 +5,7 @@
@using Microsoft.Extensions.Options
@model ErrorPageModel
@inject IOptions Instance
+@inject IOptions Security
@{
// Not meant for direct consumption, use with RazorViewRenderService.
Layout = null;
@@ -41,18 +42,16 @@
}
@if (Model.Error.Errors is { Count: > 0 } errors)
{
-
- @foreach (var error in errors)
- {
- @error.Key
-
- @foreach (var val in error.Value)
- {
- - @val
- }
-
- }
-
+ @foreach (var error in errors)
+ {
+ @error.Key
+
+ @foreach (var val in error.Value)
+ {
+ - @val
+ }
+
+ }
}
@if (Model.Error.Source != null)
{
@@ -65,6 +64,12 @@
Request ID:
@Model.Error.RequestId
+
+@if (Security.Value.ExceptionVerbosity >= ExceptionVerbosity.Debug)
+{
+ @Model.Error.Exception.ToString()
+}
+