Improve error reporting on unexpected HTTP status code

This commit is contained in:
Tyrrrz
2023-07-25 18:59:05 +03:00
parent bcf652edbe
commit ddfbe51cfa
4 changed files with 52 additions and 39 deletions

View File

@@ -1,9 +1,8 @@
using System;
using System.Net.Http;
namespace DiscordChatExporter.Core.Exceptions;
public partial class DiscordChatExporterException : Exception
public class DiscordChatExporterException : Exception
{
public bool IsFatal { get; }
@@ -12,33 +11,4 @@ public partial class DiscordChatExporterException : Exception
{
IsFatal = isFatal;
}
}
public partial class DiscordChatExporterException
{
internal static DiscordChatExporterException FailedHttpRequest(HttpResponseMessage response)
{
var message = $@"
Failed to perform an HTTP request.
[Request]
{response.RequestMessage}
[Response]
{response}";
return new DiscordChatExporterException(message.Trim(), true);
}
internal static DiscordChatExporterException Unauthorized() =>
new("Authentication token is invalid.", true);
internal static DiscordChatExporterException Forbidden() =>
new("Access is forbidden.");
internal static DiscordChatExporterException NotFound(string resourceId) =>
new($"Requested resource ({resourceId}) does not exist.");
internal static DiscordChatExporterException ChannelIsEmpty() =>
new("Channel is empty or contains no messages for the specified period.");
}