[backend/asp] Add ExceptionVerbosity level Debug

This commit is contained in:
Laura Hausmann 2024-11-16 22:45:06 +01:00
parent f252c1a85e
commit 4af69a6afa
No known key found for this signature in database
GPG key ID: D044E84C5BE01605
3 changed files with 28 additions and 18 deletions

View file

@ -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,
}

View file

@ -5,6 +5,7 @@
@using Microsoft.Extensions.Options
@model ErrorPageModel
@inject IOptions<Config.InstanceSection> Instance
@inject IOptions<Config.SecuritySection> Security
@{
// Not meant for direct consumption, use with RazorViewRenderService.
Layout = null;
@ -41,7 +42,6 @@
}
@if (Model.Error.Errors is { Count: > 0 } errors)
{
<p>
@foreach (var error in errors)
{
<strong>@error.Key</strong>
@ -52,7 +52,6 @@
}
</ul>
}
</p>
}
@if (Model.Error.Source != null)
{
@ -65,6 +64,12 @@
<strong>Request ID:</strong>
<code>@Model.Error.RequestId</code>
</p>
@if (Security.Value.ExceptionVerbosity >= ExceptionVerbosity.Debug)
{
<pre><code>@Model.Error.Exception.ToString()</code></pre>
}
<footer>
<strong>Iceshrimp.NET</strong> v@(Instance.Value.Version)
@if (Model.Error.Exception is PublicPreviewDisabledException)

View file

@ -43,7 +43,11 @@ AllowLocalIPv4 = false
AllowLocalIPv6 = false
;; The level of detail in API error responses
;; Options: [None, Basic, Full]
;; Options: [None, Basic, Full, Verbose]
;; - 'None' only returns the request identifier & status code
;; - 'Basic' adds the error code & message
;; - 'Full' adds error details (if any) and the name of the class that caused the exception
;; - 'Debug' adds the stack trace (HTML only)
ExceptionVerbosity = Basic
;; Whether to allow instance registrations