Improve error handling and reporting after command rewrite

This commit is contained in:
Ske
2019-10-22 19:31:40 +02:00
parent 284e8eb95a
commit 53ae0e3d70
3 changed files with 57 additions and 4 deletions

View File

@@ -2,9 +2,11 @@ using System;
using System.Globalization;
using System.Linq;
using System.Net.Http;
using System.Net.Sockets;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Discord;
using Discord.Net;
using PluralKit.Core;
using Image = SixLabors.ImageSharp.Image;
@@ -117,6 +119,24 @@ namespace PluralKit.Bot
public static async Task<bool> HasPermission(this IChannel channel, ChannelPermission permission) =>
(await PermissionsIn(channel)).Has(permission);
public static bool IsOurProblem(this Exception e)
{
// This function filters out sporadic errors out of our control from being reported to Sentry
// otherwise we'd blow out our error reporting budget as soon as Discord takes a dump, or something.
// Discord server errors are *not our problem*
if (e is HttpException he && ((int) he.HttpCode) >= 500) return false;
// Socket errors are *not our problem*
if (e is SocketException) return false;
// Tasks being cancelled for whatver reason are, you guessed it, also not our problem.
if (e is TaskCanceledException) return false;
// This may expanded at some point.
return true;
}
}
/// <summary>