Skip to content

Commit

Permalink
feat(tenants): error code when tenant does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
colinin committed Sep 16, 2024
1 parent 98e9f94 commit c5af9ed
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public async virtual Task<TenantDto> GetAsync(Guid id)
var tenant = await TenantRepository.FindAsync(id);
if (tenant == null)
{
throw new UserFriendlyException(L["TenantNotFoundById", id]);
throw new BusinessException(AbpSaasErrorCodes.TenantIdOrNameNotFound)
.WithData("Tenant", id);
}

return ObjectMapper.Map<Tenant, TenantDto>(tenant);
Expand All @@ -50,7 +51,8 @@ public async virtual Task<TenantDto> GetAsync(string name)
var tenant = await TenantRepository.FindByNameAsync(name);
if (tenant == null)
{
throw new UserFriendlyException(L["TenantNotFoundByName", name]);
throw new BusinessException(AbpSaasErrorCodes.TenantIdOrNameNotFound)
.WithData("Tenant", name);
}
return ObjectMapper.Map<Tenant, TenantDto>(tenant);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,23 @@
public static class AbpSaasErrorCodes
{
public const string Namespace = "Saas";

/// <summary>
/// 已经存在名为 {DisplayName} 的版本!
/// </summary>
public const string DuplicateEditionDisplayName = Namespace + ":010001";
/// <summary>
/// 试图删除正在使用的版本: {DisplayName}!
/// </summary>
public const string DeleteUsedEdition = Namespace + ":010002";
/// <summary>
/// 已经存在名为 {Name} 的租户!
/// </summary>
public const string DuplicateTenantName = Namespace + ":020001";
/// <summary>
/// 租户: {Tenant} 不存在!
/// </summary>
public const string TenantIdOrNameNotFound = Namespace + ":020002";
/// <summary>
/// 无效的默认连接字符串
/// </summary>
public const string InvalidDefaultConnectionString = Namespace + ":020101";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"Saas:010001": "Unable to create duplicate editions {DisplayName}!",
"Saas:010002": "Tried to delete the edition in use: {DisplayName}!",
"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:020102": "The database pointed to by the default connection string already exists!",
"Saas:020103": "Unable to open the database connection pointed to by {Name}!",
Expand Down Expand Up @@ -47,8 +48,6 @@
"Features:ExpirationReminderDaysDesc": "Send a reminder to the administrator when the resource has how many days left to expire",
"Features:ExpiredRecoveryTime": "Expired Recovery Time",
"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",
"RecycleStrategy:Reserve": "Reserve",
"RecycleStrategy:Recycle": "Recycle"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"Saas:010001": "已经存在名为 {DisplayName} 的版本!",
"Saas:010002": "试图删除正在使用的版本: {DisplayName}!",
"Saas:020001": "已经存在名为 {Name} 的租户!",
"Saas:020002": "租户: {Tenant} 不存在!",
"Saas:020101": "无法打开默认连接字符串指向的数据库连接!",
"Saas:020102": "默认连接字符串指向的数据库已经存在!",
"Saas:020103": "无法打开 {Name} 指向的数据库连接!",
Expand Down Expand Up @@ -47,8 +48,6 @@
"Features:ExpirationReminderDaysDesc": "当资源还有多少天过期时, 给管理员发送提醒",
"Features:ExpiredRecoveryTime": "过期回收时长",
"Features:ExpiredRecoveryTimeDesc": "当资源超期多久没有处理, 将回收租户资源",
"TenantNotFoundById": "租户: {0} 不存在!",
"TenantNotFoundByName": "租户: {0} 不存在!",
"UnActived": "未启用",
"RecycleStrategy:Reserve": "保留",
"RecycleStrategy:Recycle": "回收"
Expand Down

0 comments on commit c5af9ed

Please sign in to comment.