Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 28 additions & 15 deletions src/Umbraco.Cms.ManagementApi/ManagementApiComposer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,24 +84,37 @@ public void Compose(IUmbracoBuilder builder)
"BackofficeSwagger",
applicationBuilder =>
{
applicationBuilder.UseExceptionHandler(exceptionBuilder => exceptionBuilder.Run(async context =>
{
Exception? exception = context.Features.Get<IExceptionHandlerPathFeature>()?.Error;
if (exception is null)
// Only use the API exception handler when we are requesting an API
applicationBuilder.UseWhen(
httpContext =>
{
return;
}
GlobalSettings? settings = httpContext.RequestServices.GetRequiredService<IOptions<GlobalSettings>>().Value;
IHostingEnvironment hostingEnvironment = httpContext.RequestServices.GetRequiredService<IHostingEnvironment>();
var officePath = settings.GetBackOfficePath(hostingEnvironment);

var response = new ProblemDetails
return httpContext.Request.Path.Value?.StartsWith($"{officePath}/management/api/") ?? false;
},
innerBuilder =>
{
Title = exception.Message,
Detail = exception.StackTrace,
Status = StatusCodes.Status500InternalServerError,
Instance = exception.GetType().Name,
Type = "Error",
};
await context.Response.WriteAsJsonAsync(response);
}));
innerBuilder.UseExceptionHandler(exceptionBuilder => exceptionBuilder.Run(async context =>
{
Exception? exception = context.Features.Get<IExceptionHandlerPathFeature>()?.Error;
if (exception is null)
{
return;
}

var response = new ProblemDetails
{
Title = exception.Message,
Detail = exception.StackTrace,
Status = StatusCodes.Status500InternalServerError,
Instance = exception.GetType().Name,
Type = "Error",
};
await context.Response.WriteAsJsonAsync(response);
}));
});
},
applicationBuilder =>
{
Expand Down