Create GetXXX utils wrapping try blocks

This commit is contained in:
Ske
2020-07-02 18:29:04 +02:00
parent 7fef8c1dde
commit c87e67245d
8 changed files with 95 additions and 49 deletions

View File

@@ -50,11 +50,9 @@ namespace PluralKit.Bot {
private async Task<DiscordChannel> FindLogChannel(ulong guild, ulong channel)
{
try
{
return await _rest.GetChannelAsync(channel);
}
catch (Exception e) when (e is NotFoundException || e is UnauthorizedException)
var obj = await _rest.GetChannel(channel);
if (obj == null)
{
// Channel doesn't exist or we don't have permission to access it, let's remove it from the database too
_logger.Warning("Attempted to fetch missing log channel {LogChannel}, removing from database", channel);
@@ -63,7 +61,7 @@ namespace PluralKit.Bot {
new {Guild = guild});
}
return null;
return obj;
}
}
}