Merge pull request #7321 from abpframework/maliming/patch-1

Localize exception message in pages.
pull/7355/head
Halil İbrahim Kalkan 5 years ago committed by GitHub
commit 66846a4477
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -8,6 +8,7 @@ using Volo.Abp.AspNetCore.Mvc.UI.Bundling;
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared; using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared;
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Toolbars; using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Toolbars;
using Volo.Abp.AutoMapper; using Volo.Abp.AutoMapper;
using Volo.Abp.ExceptionHandling;
using Volo.Abp.Identity.AspNetCore; using Volo.Abp.Identity.AspNetCore;
using Volo.Abp.Modularity; using Volo.Abp.Modularity;
using Volo.Abp.UI.Navigation; using Volo.Abp.UI.Navigation;
@ -19,7 +20,8 @@ namespace Volo.Abp.Account.Web
typeof(AbpAccountHttpApiModule), typeof(AbpAccountHttpApiModule),
typeof(AbpIdentityAspNetCoreModule), typeof(AbpIdentityAspNetCoreModule),
typeof(AbpAutoMapperModule), typeof(AbpAutoMapperModule),
typeof(AbpAspNetCoreMvcUiThemeSharedModule) typeof(AbpAspNetCoreMvcUiThemeSharedModule),
typeof(AbpExceptionHandlingModule)
)] )]
public class AbpAccountWebModule : AbpModule public class AbpAccountWebModule : AbpModule
{ {

@ -2,10 +2,11 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Volo.Abp.Account.Localization; using Volo.Abp.Account.Localization;
using Volo.Abp.AspNetCore.ExceptionHandling;
using Volo.Abp.AspNetCore.Mvc.UI.RazorPages; using Volo.Abp.AspNetCore.Mvc.UI.RazorPages;
using Volo.Abp.ExceptionHandling;
using Volo.Abp.Identity; using Volo.Abp.Identity;
using IdentityUser = Volo.Abp.Identity.IdentityUser; using IdentityUser = Volo.Abp.Identity.IdentityUser;
@ -18,6 +19,7 @@ namespace Volo.Abp.Account.Web.Pages.Account
public IdentityUserManager UserManager { get; set; } public IdentityUserManager UserManager { get; set; }
public IdentitySecurityLogManager IdentitySecurityLogManager { get; set; } public IdentitySecurityLogManager IdentitySecurityLogManager { get; set; }
public IOptions<IdentityOptions> IdentityOptions { get; set; } public IOptions<IdentityOptions> IdentityOptions { get; set; }
public IExceptionToErrorInfoConverter ExceptionToErrorInfoConverter { get; set; }
protected AccountPageModel() protected AccountPageModel()
{ {
@ -42,5 +44,15 @@ namespace Volo.Abp.Account.Web.Pages.Account
throw new ApplicationException($"Current tenant is different than given tenant. CurrentTenant.Id: {CurrentTenant.Id}, given tenantId: {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;
}
} }
} }

@ -43,7 +43,7 @@ namespace Volo.Abp.Account.Web.Pages.Account
} }
catch (UserFriendlyException e) catch (UserFriendlyException e)
{ {
Alerts.Danger(e.Message); Alerts.Danger(GetLocalizeExceptionMessage(e));
return Page(); return Page();
} }

@ -1,8 +1,6 @@
using System;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.Linq; using System.Linq;
using System.Security.Claims; using System.Security.Claims;
using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@ -100,7 +98,7 @@ namespace Volo.Abp.Account.Web.Pages.Account
} }
catch (BusinessException e) catch (BusinessException e)
{ {
Alerts.Danger(e.Message); Alerts.Danger(GetLocalizeExceptionMessage(e));
return Page(); return Page();
} }
} }

@ -82,7 +82,7 @@ namespace Volo.Abp.Account.Web.Pages.Account
{ {
if (!string.IsNullOrWhiteSpace(e.Message)) if (!string.IsNullOrWhiteSpace(e.Message))
{ {
Alerts.Warning(e.Message); Alerts.Warning(GetLocalizeExceptionMessage(e));
return Page(); return Page();
} }

Loading…
Cancel
Save