[CLI] Fix missing channel category bug when API returns empty string (#492)

This commit is contained in:
Frederic Portaria-Janicki
2021-02-02 07:42:04 -05:00
committed by GitHub
parent 8b9afe45b9
commit e49cf997ea
2 changed files with 16 additions and 3 deletions

View File

@@ -171,9 +171,20 @@ namespace DiscordChatExporter.Domain.Discord
public async ValueTask<ChannelCategory> GetChannelCategoryAsync(Snowflake channelId)
{
var response = await GetJsonResponseAsync($"channels/{channelId}");
try
{
var response = await GetJsonResponseAsync($"channels/{channelId}");
return ChannelCategory.Parse(response);
}
/***
* In some cases, the Discord API returns an empty body when requesting some channel category info.
* Instead, we use an empty channel category as a fallback.
*/
catch (DiscordChatExporterException)
{
return ChannelCategory.Empty;
}
return ChannelCategory.Parse(response);
}
public async ValueTask<Channel> GetChannelAsync(Snowflake channelId)

View File

@@ -44,5 +44,7 @@ namespace DiscordChatExporter.Domain.Discord.Models
position.Value
);
}
public static ChannelCategory Empty { get; } = new(Snowflake.Zero, "Missing", 0);
}
}
}