using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.Extensions.Logging; namespace Api.SeaHavenIndustries.Filters { /// /// Anonymous invite endpoints never echo an exception: controller-scoped exception /// filters run before the global ones, so no message, stack or SQL reaches the caller. /// Cancellation is left to the host. /// public sealed class InviteRegistrationExceptionFilter : IExceptionFilter { public const string Message = "Something went wrong. Try again in a minute."; private readonly ILogger _logger; public InviteRegistrationExceptionFilter(ILogger logger) { _logger = logger; } public void OnException(ExceptionContext context) { if (context.Exception is OperationCanceledException) return; _logger.LogError(context.Exception, "Invite registration request failed."); context.Result = new ObjectResult(new { code = "server_error", message = Message, retryAfterSeconds = (int?)null }) { StatusCode = StatusCodes.Status500InternalServerError }; context.ExceptionHandled = true; } } }