Skip to content

Commit b76070c

Browse files
bergmaniaZeegaan
authored andcommitted
Merge commit from fork
* Use Debug Mode to determine content of the ProblemDetails * Cache the debug value
1 parent 72bef88 commit b76070c

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

src/Umbraco.Cms.Api.Management/DependencyInjection/ApplicationBuilderExtensions.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ internal static IApplicationBuilder UseProblemDetailsExceptionHandling(this IApp
3333
{
3434
innerBuilder.UseExceptionHandler(exceptionBuilder => exceptionBuilder.Run(async context =>
3535
{
36+
var isDebug = context.RequestServices.GetRequiredService<IHostingEnvironment>().IsDebugMode;
3637
Exception? exception = context.Features.Get<IExceptionHandlerPathFeature>()?.Error;
3738
if (exception is null)
3839
{
@@ -42,16 +43,16 @@ internal static IApplicationBuilder UseProblemDetailsExceptionHandling(this IApp
4243
var response = new ProblemDetails
4344
{
4445
Title = exception.Message,
45-
Detail = exception.StackTrace,
46+
Detail = isDebug ? exception.StackTrace : null,
4647
Status = StatusCodes.Status500InternalServerError,
47-
Instance = exception.GetType().Name,
48+
Instance = isDebug ? exception.GetType().Name : null,
4849
Type = "Error"
4950
};
5051
await context.Response.WriteAsJsonAsync(response);
5152
}));
5253
});
5354

54-
internal static IApplicationBuilder UseEndpoints(this IApplicationBuilder applicationBuilder)
55+
internal static IApplicationBuilder UseEndpoints(this IApplicationBuilder applicationBuilder)
5556
{
5657
IServiceProvider provider = applicationBuilder.ApplicationServices;
5758

src/Umbraco.Web.Common/AspNetCore/AspNetCoreHostingEnvironment.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ public AspNetCoreHostingEnvironment(
4343
_webHostEnvironment = webHostEnvironment ?? throw new ArgumentNullException(nameof(webHostEnvironment));
4444
_urlProviderMode = _webRoutingSettings.CurrentValue.UrlProviderMode;
4545

46-
SetSiteName(hostingSettings.CurrentValue.SiteName);
46+
SetSiteNameAndDebugMode(hostingSettings.CurrentValue);
4747

4848
// We have to ensure that the OptionsMonitor is an actual options monitor since we have a hack
4949
// where we initially use an OptionsMonitorAdapter, which doesn't implement OnChange.
5050
// See summery of OptionsMonitorAdapter for more information.
5151
if (hostingSettings is OptionsMonitor<HostingSettings>)
5252
{
53-
hostingSettings.OnChange(settings => SetSiteName(settings.SiteName));
53+
hostingSettings.OnChange(settings => SetSiteNameAndDebugMode(settings));
5454
}
5555

5656
ApplicationPhysicalPath = webHostEnvironment.ContentRootPath;
@@ -95,7 +95,7 @@ public string ApplicationId
9595
_hostingSettings.CurrentValue.ApplicationVirtualPath?.EnsureStartsWith('/') ?? "/";
9696

9797
/// <inheritdoc />
98-
public bool IsDebugMode => _hostingSettings.CurrentValue.Debug;
98+
public bool IsDebugMode { get; private set; }
9999

100100
public string LocalTempPath
101101
{
@@ -188,8 +188,12 @@ public void EnsureApplicationMainUrl(Uri? currentApplicationUrl)
188188
}
189189
}
190190

191-
private void SetSiteName(string? siteName) =>
192-
SiteName = string.IsNullOrWhiteSpace(siteName)
191+
private void SetSiteNameAndDebugMode(HostingSettings hostingSettings)
192+
{
193+
SiteName = string.IsNullOrWhiteSpace(hostingSettings.SiteName)
193194
? _webHostEnvironment.ApplicationName
194-
: siteName;
195+
: hostingSettings.SiteName;
196+
197+
IsDebugMode = hostingSettings.Debug;
198+
}
195199
}

0 commit comments

Comments
 (0)