2020-02-12 14:16:19 +00:00
|
|
|
using System;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Net.Sockets;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
2020-05-05 17:09:18 +00:00
|
|
|
using DSharpPlus.Exceptions;
|
|
|
|
|
2020-03-08 09:55:33 +00:00
|
|
|
using Npgsql;
|
|
|
|
|
2020-02-12 14:16:19 +00:00
|
|
|
using PluralKit.Core;
|
|
|
|
|
|
|
|
namespace PluralKit.Bot
|
|
|
|
{
|
|
|
|
public static class MiscUtils {
|
|
|
|
public static string ProxyTagsString(this PKMember member) => string.Join(", ", member.ProxyTags.Select(t => $"`{t.ProxyString.EscapeMarkdown()}`"));
|
|
|
|
|
|
|
|
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*
|
2020-04-17 21:10:01 +00:00
|
|
|
// TODO
|
|
|
|
// if (e is DSharpPlus.Exceptions he && ((int) he.HttpCode) >= 500) return false;
|
2020-02-12 14:16:19 +00:00
|
|
|
|
2020-02-26 18:47:30 +00:00
|
|
|
// Webhook server errors are also *not our problem*
|
2020-03-26 23:01:42 +00:00
|
|
|
// (this includes rate limit errors, WebhookRateLimited is a subclass)
|
2020-02-26 18:47:30 +00:00
|
|
|
if (e is WebhookExecutionErrorOnDiscordsEnd) return false;
|
|
|
|
|
2020-02-12 14:16:19 +00:00
|
|
|
// 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;
|
2020-02-18 20:56:15 +00:00
|
|
|
|
|
|
|
// Sometimes Discord just times everything out.
|
|
|
|
if (e is TimeoutException) return false;
|
2020-02-12 14:16:19 +00:00
|
|
|
|
2020-03-08 09:55:33 +00:00
|
|
|
// Ignore "Database is shutting down" error
|
|
|
|
if (e is PostgresException pe && pe.SqlState == "57P03") return false;
|
|
|
|
|
2020-02-12 14:16:19 +00:00
|
|
|
// This may expanded at some point.
|
|
|
|
return true;
|
|
|
|
}
|
2020-05-05 17:09:18 +00:00
|
|
|
|
|
|
|
public static string ExtractError(BadRequestException e)
|
|
|
|
{
|
|
|
|
return e.WebResponse.Response;
|
|
|
|
}
|
2020-02-12 14:16:19 +00:00
|
|
|
}
|
|
|
|
}
|