Base solution for your next web application
Open Closed

Throwing UserFriendlyException not working #5577


User avatar
0
OriAssurant created

I am not able to use UserFriendlyException from Account controller it doesnt give me expected pop up message Please help


4 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team

    Please share some code.

  • User Avatar
    0
    ryancyq created
    Support Team

    Hi, please share your the code for the method where UserFriendlyException is thrown.

    Also, Ajax response for the method as well.

  • User Avatar
    0
    OriAssurant created

    Here are two ways I use for throwing UserFriendlyException in GetLoginResultAsync:

    var loginResult = await GetLoginResultAsync(loginModel.UsernameOrEmailAddress, loginModel.Password, loginModel.TenancyName,LoginCount);

    throw new UserFriendlyException(L("PasswordAttempts")); throw new UserFriendlyException(L("LoginFailed"), L("InvalidUserNameOrPassword"));

    In logs.txt, I can see Abp.UI.UserFriendlyException: Login failed! at Project.Web.Controllers.AccountController.<GetLoginResultAsync>d__28.MoveNext() in C:\Projects\Project.Web\Controllers\AccountController.cs:line 248

    In application insights, I saw: The model item passed into the dictionary is of type 'System.Web.Mvc.HandleErrorInfo', but this dictionary requires a model item of type 'Abp.Web.Mvc.Models.ErrorViewModel'.

    Forgot to mention, we're using application insights filter:

    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = true)] 
    public class AiHandleErrorAttribute : HandleErrorAttribute
    {
        public override void OnException(ExceptionContext filterContext)
        {
            if (filterContext != null && filterContext.HttpContext != null && filterContext.Exception != null)
            {
                //If customError is Off, then AI HTTPModule will report the exception
                if (filterContext.HttpContext.IsCustomErrorEnabled)
                {   
                    var ai = new TelemetryClient();
                    ai.TrackException(filterContext.Exception);
                }
            }
        }
    }
    

    Thank you

  • User Avatar
    0
    alper created
    Support Team

    does it work as expected when you disable Application Insights?