public override void OnException(ExceptionContext context) { var actionDescriptor = (Microsoft.AspNetCore.Mvc.Controllers.ControllerActionDescriptor)context.ActionDescriptor; Type controllerType = actionDescriptor.ControllerTypeInfo; var error = context.Exception; switch (error) { case AggregateException ae: { foreach (var innerException in ae.Flatten().InnerExceptions) { _logger.Err("Task failed", innerException); } _toast.AddErrorToastMessage(RawStrings.GENERIC_APP_Error); break; } case UserLevelException _: _toast.AddErrorToastMessage(error.Message); _logger.Warn("User error occurred.", error); break; default: _logger.Err(error.Message, null); _toast.AddErrorToastMessage(RawStrings.GENERIC_APP_Error); break; } // redirect to the controller that was specified context.Result = new RedirectToRouteResult( new RouteValueDictionary { { "controller", ControllerName }, { "action", ViewName } }); context.ExceptionHandled = true; }