Skip to content

Commit

Permalink
Merge pull request #7321 from abpframework/maliming/patch-1
Browse files Browse the repository at this point in the history
Localize exception message in pages.
  • Loading branch information
hikalkan committed Jan 19, 2021
2 parents 1eddebf + cc1c1d3 commit 66846a4
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared;
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Toolbars;
using Volo.Abp.AutoMapper;
using Volo.Abp.ExceptionHandling;
using Volo.Abp.Identity.AspNetCore;
using Volo.Abp.Modularity;
using Volo.Abp.UI.Navigation;
Expand All @@ -19,7 +20,8 @@ namespace Volo.Abp.Account.Web
typeof(AbpAccountHttpApiModule),
typeof(AbpIdentityAspNetCoreModule),
typeof(AbpAutoMapperModule),
typeof(AbpAspNetCoreMvcUiThemeSharedModule)
typeof(AbpAspNetCoreMvcUiThemeSharedModule),
typeof(AbpExceptionHandlingModule)
)]
public class AbpAccountWebModule : AbpModule
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using Volo.Abp.Account.Localization;
using Volo.Abp.AspNetCore.ExceptionHandling;
using Volo.Abp.AspNetCore.Mvc.UI.RazorPages;
using Volo.Abp.ExceptionHandling;
using Volo.Abp.Identity;
using IdentityUser = Volo.Abp.Identity.IdentityUser;

Expand All @@ -18,6 +19,7 @@ public abstract class AccountPageModel : AbpPageModel
public IdentityUserManager UserManager { get; set; }
public IdentitySecurityLogManager IdentitySecurityLogManager { get; set; }
public IOptions<IdentityOptions> IdentityOptions { get; set; }
public IExceptionToErrorInfoConverter ExceptionToErrorInfoConverter { get; set; }

protected AccountPageModel()
{
Expand All @@ -42,5 +44,15 @@ protected virtual void CheckCurrentTenant(Guid? tenantId)
throw new ApplicationException($"Current tenant is different than given tenant. CurrentTenant.Id: {CurrentTenant.Id}, given tenantId: {tenantId}");
}
}

protected virtual string GetLocalizeExceptionMessage(Exception exception)
{
if (exception is ILocalizeErrorMessage || exception is IHasErrorCode)
{
return ExceptionToErrorInfoConverter.Convert(exception, false).Message;
}

return exception.Message;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public virtual async Task<IActionResult> OnPostAsync()
}
catch (UserFriendlyException e)
{
Alerts.Danger(e.Message);
Alerts.Danger(GetLocalizeExceptionMessage(e));
return Page();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
Expand Down Expand Up @@ -100,7 +98,7 @@ public virtual async Task<IActionResult> OnPostAsync()
}
catch (BusinessException e)
{
Alerts.Danger(e.Message);
Alerts.Danger(GetLocalizeExceptionMessage(e));
return Page();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public virtual async Task<IActionResult> OnPostAsync()
{
if (!string.IsNullOrWhiteSpace(e.Message))
{
Alerts.Warning(e.Message);
Alerts.Warning(GetLocalizeExceptionMessage(e));
return Page();
}

Expand Down

0 comments on commit 66846a4

Please sign in to comment.