slightly more graceful error handling

This commit is contained in:
Adam R Grey 2023-03-02 00:10:49 -05:00
parent def4f3644e
commit c874e3e421

View File

@ -37,14 +37,22 @@ namespace silverworker_discord
string path = res.Data; string path = res.Data;
if (File.Exists(path)) if (File.Exists(path))
{ {
try var bytesize = new System.IO.FileInfo(path).Length;
if(bytesize < 1024*1024*10)
{ {
await message.Channel.SendFileAsync(path); try
{
await message.Channel.SendFileAsync(path);
}
catch (Exception e)
{
System.Console.Error.WriteLine(e);
await message.Channel.SendMessageAsync($"aaaadam!\n{e}");
}
} }
catch (Exception e) else
{ {
System.Console.Error.WriteLine(JsonConvert.SerializeObject(e)); Console.WriteLine($"file appears too big ({bytesize} bytes ({bytesize / (1024*1024)}MB)), not posting");
await message.Channel.SendMessageAsync($"aaaadam!\n{JsonConvert.SerializeObject(e)}");
} }
File.Delete(path); File.Delete(path);
} }