Browse Source

feat(tenants): error code when tenant does not exist

pull/1005/head
colin 1 year ago
parent
commit
c5af9ed27a
  1. 6
      aspnet-core/modules/saas/LINGYUN.Abp.Saas.Application/LINGYUN/Abp/Saas/Tenants/TenantAppService.cs
  2. 14
      aspnet-core/modules/saas/LINGYUN.Abp.Saas.Domain.Shared/LINGYUN/Abp/Saas/AbpSaasErrorCodes.cs
  3. 3
      aspnet-core/modules/saas/LINGYUN.Abp.Saas.Domain.Shared/LINGYUN/Abp/Saas/Localization/Resources/en.json
  4. 3
      aspnet-core/modules/saas/LINGYUN.Abp.Saas.Domain.Shared/LINGYUN/Abp/Saas/Localization/Resources/zh-Hans.json

6
aspnet-core/modules/saas/LINGYUN.Abp.Saas.Application/LINGYUN/Abp/Saas/Tenants/TenantAppService.cs

@ -39,7 +39,8 @@ public class TenantAppService : AbpSaasAppServiceBase, ITenantAppService
var tenant = await TenantRepository.FindAsync(id); var tenant = await TenantRepository.FindAsync(id);
if (tenant == null) if (tenant == null)
{ {
throw new UserFriendlyException(L["TenantNotFoundById", id]); throw new BusinessException(AbpSaasErrorCodes.TenantIdOrNameNotFound)
.WithData("Tenant", id);
} }
return ObjectMapper.Map<Tenant, TenantDto>(tenant); return ObjectMapper.Map<Tenant, TenantDto>(tenant);
@ -50,7 +51,8 @@ public class TenantAppService : AbpSaasAppServiceBase, ITenantAppService
var tenant = await TenantRepository.FindByNameAsync(name); var tenant = await TenantRepository.FindByNameAsync(name);
if (tenant == null) if (tenant == null)
{ {
throw new UserFriendlyException(L["TenantNotFoundByName", name]); throw new BusinessException(AbpSaasErrorCodes.TenantIdOrNameNotFound)
.WithData("Tenant", name);
} }
return ObjectMapper.Map<Tenant, TenantDto>(tenant); return ObjectMapper.Map<Tenant, TenantDto>(tenant);
} }

14
aspnet-core/modules/saas/LINGYUN.Abp.Saas.Domain.Shared/LINGYUN/Abp/Saas/AbpSaasErrorCodes.cs

@ -3,11 +3,23 @@
public static class AbpSaasErrorCodes public static class AbpSaasErrorCodes
{ {
public const string Namespace = "Saas"; public const string Namespace = "Saas";
/// <summary>
/// 已经存在名为 {DisplayName} 的版本!
/// </summary>
public const string DuplicateEditionDisplayName = Namespace + ":010001"; public const string DuplicateEditionDisplayName = Namespace + ":010001";
/// <summary>
/// 试图删除正在使用的版本: {DisplayName}!
/// </summary>
public const string DeleteUsedEdition = Namespace + ":010002"; public const string DeleteUsedEdition = Namespace + ":010002";
/// <summary>
/// 已经存在名为 {Name} 的租户!
/// </summary>
public const string DuplicateTenantName = Namespace + ":020001"; public const string DuplicateTenantName = Namespace + ":020001";
/// <summary> /// <summary>
/// 租户: {Tenant} 不存在!
/// </summary>
public const string TenantIdOrNameNotFound = Namespace + ":020002";
/// <summary>
/// 无效的默认连接字符串 /// 无效的默认连接字符串
/// </summary> /// </summary>
public const string InvalidDefaultConnectionString = Namespace + ":020101"; public const string InvalidDefaultConnectionString = Namespace + ":020101";

3
aspnet-core/modules/saas/LINGYUN.Abp.Saas.Domain.Shared/LINGYUN/Abp/Saas/Localization/Resources/en.json

@ -4,6 +4,7 @@
"Saas:010001": "Unable to create duplicate editions {DisplayName}!", "Saas:010001": "Unable to create duplicate editions {DisplayName}!",
"Saas:010002": "Tried to delete the edition in use: {DisplayName}!", "Saas:010002": "Tried to delete the edition in use: {DisplayName}!",
"Saas:020001": "Unable to create duplicate tenants {Name}!", "Saas:020001": "Unable to create duplicate tenants {Name}!",
"Saas:020002": "Tenant: {Tenant} not found!",
"Saas:020101": "The default connection string cannot open a connection to the database!", "Saas:020101": "The default connection string cannot open a connection to the database!",
"Saas:020102": "The database pointed to by the default connection string already exists!", "Saas:020102": "The database pointed to by the default connection string already exists!",
"Saas:020103": "Unable to open the database connection pointed to by {Name}!", "Saas:020103": "Unable to open the database connection pointed to by {Name}!",
@ -47,8 +48,6 @@
"Features:ExpirationReminderDaysDesc": "Send a reminder to the administrator when the resource has how many days left to expire", "Features:ExpirationReminderDaysDesc": "Send a reminder to the administrator when the resource has how many days left to expire",
"Features:ExpiredRecoveryTime": "Expired Recovery Time", "Features:ExpiredRecoveryTime": "Expired Recovery Time",
"Features:ExpiredRecoveryTimeDesc": "If the resource expiration is not handled for a long time, tenant resources will be reclaimed", "Features:ExpiredRecoveryTimeDesc": "If the resource expiration is not handled for a long time, tenant resources will be reclaimed",
"TenantNotFoundById": "Tenant: {0} not found!",
"TenantNotFoundByName": "Tenant: {0} not found!",
"UnActived": "UnActived", "UnActived": "UnActived",
"RecycleStrategy:Reserve": "Reserve", "RecycleStrategy:Reserve": "Reserve",
"RecycleStrategy:Recycle": "Recycle" "RecycleStrategy:Recycle": "Recycle"

3
aspnet-core/modules/saas/LINGYUN.Abp.Saas.Domain.Shared/LINGYUN/Abp/Saas/Localization/Resources/zh-Hans.json

@ -4,6 +4,7 @@
"Saas:010001": "已经存在名为 {DisplayName} 的版本!", "Saas:010001": "已经存在名为 {DisplayName} 的版本!",
"Saas:010002": "试图删除正在使用的版本: {DisplayName}!", "Saas:010002": "试图删除正在使用的版本: {DisplayName}!",
"Saas:020001": "已经存在名为 {Name} 的租户!", "Saas:020001": "已经存在名为 {Name} 的租户!",
"Saas:020002": "租户: {Tenant} 不存在!",
"Saas:020101": "无法打开默认连接字符串指向的数据库连接!", "Saas:020101": "无法打开默认连接字符串指向的数据库连接!",
"Saas:020102": "默认连接字符串指向的数据库已经存在!", "Saas:020102": "默认连接字符串指向的数据库已经存在!",
"Saas:020103": "无法打开 {Name} 指向的数据库连接!", "Saas:020103": "无法打开 {Name} 指向的数据库连接!",
@ -47,8 +48,6 @@
"Features:ExpirationReminderDaysDesc": "当资源还有多少天过期时, 给管理员发送提醒", "Features:ExpirationReminderDaysDesc": "当资源还有多少天过期时, 给管理员发送提醒",
"Features:ExpiredRecoveryTime": "过期回收时长", "Features:ExpiredRecoveryTime": "过期回收时长",
"Features:ExpiredRecoveryTimeDesc": "当资源超期多久没有处理, 将回收租户资源", "Features:ExpiredRecoveryTimeDesc": "当资源超期多久没有处理, 将回收租户资源",
"TenantNotFoundById": "租户: {0} 不存在!",
"TenantNotFoundByName": "租户: {0} 不存在!",
"UnActived": "未启用", "UnActived": "未启用",
"RecycleStrategy:Reserve": "保留", "RecycleStrategy:Reserve": "保留",
"RecycleStrategy:Recycle": "回收" "RecycleStrategy:Recycle": "回收"

Loading…
Cancel
Save