using Microsoft.AspNetCore.Mvc; namespace Cleanuparr.Api.Extensions; public static class ControllerBaseExtensions { /// /// Builds an RFC 9457 problem-details error response for a direct (non-throwing) controller return. /// Mirrors the shape produced by so every error /// response carries the same application/problem+json body and traceId. The /// traceId extension is added by the shared CustomizeProblemDetails hook inside /// . /// public static ObjectResult ProblemResult( this ControllerBase controller, int statusCode, string detail, string? title = null, IReadOnlyDictionary? extensions = null) { ProblemDetails problemDetails = controller.ProblemDetailsFactory .CreateProblemDetails(controller.HttpContext, statusCode: statusCode, title: title, detail: detail); if (extensions is not null) { foreach (KeyValuePair extension in extensions) { problemDetails.Extensions[extension.Key] = extension.Value; } } return new ObjectResult(problemDetails) { StatusCode = statusCode, ContentTypes = { "application/problem+json" }, }; } }