refactor: return CataloggerError as Results instead of throwing in commands

This commit is contained in:
sam 2025-03-20 15:24:23 +01:00
parent 84c3b42874
commit 8a4e3ff184
Signed by: sam
GPG key ID: 5F3C3C1B3166639D
11 changed files with 57 additions and 36 deletions

View file

@ -45,7 +45,7 @@ public class KeyRoleCommands(
{
var (_, guildId) = contextInjection.GetUserAndGuild();
if (!guildCache.TryGet(guildId, out var guild))
throw new CataloggerError("Guild not in cache");
return CataloggerError.Result("Guild not in cache");
var guildRoles = roleCache.GuildRoles(guildId).ToList();
var guildConfig = await guildRepository.GetAsync(guildId);
@ -85,7 +85,7 @@ public class KeyRoleCommands(
var (_, guildId) = contextInjection.GetUserAndGuild();
var role = roleCache.GuildRoles(guildId).FirstOrDefault(r => r.ID == roleId);
if (role == null)
throw new CataloggerError("Role is not cached");
return CataloggerError.Result("Role is not cached");
var guildConfig = await guildRepository.GetAsync(guildId);
if (guildConfig.KeyRoles.Any(id => role.ID.Value == id))
@ -111,7 +111,7 @@ public class KeyRoleCommands(
var (_, guildId) = contextInjection.GetUserAndGuild();
var role = roleCache.GuildRoles(guildId).FirstOrDefault(r => r.ID == roleId);
if (role == null)
throw new CataloggerError("Role is not cached");
return CataloggerError.Result("Role is not cached");
var guildConfig = await guildRepository.GetAsync(guildId);
if (guildConfig.KeyRoles.All(id => role.ID != id))