This commit is contained in:
Tyrrrz
2022-12-15 20:08:14 +02:00
parent 49c4b12512
commit e5d5f1c85f
3 changed files with 15 additions and 15 deletions

View File

@@ -1,9 +1,5 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Net;
using System.Net.Http;
using System.Text.RegularExpressions;
namespace DiscordChatExporter.Core.Utils.Extensions;
@@ -32,13 +28,4 @@ public static class ExceptionExtensions
PopulateChildren(exception, children);
return children;
}
public static HttpStatusCode? TryGetStatusCode(this HttpRequestException ex) =>
// This is extremely frail, but there's no other way
Regex
.Match(ex.Message, @": (\d+) \(")
.Groups[1]
.Value
.NullIfWhiteSpace()?
.Pipe(s => (HttpStatusCode) int.Parse(s, CultureInfo.InvariantCulture));
}

View File

@@ -1,4 +1,8 @@
using System.Net.Http.Headers;
using System.Globalization;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text.RegularExpressions;
namespace DiscordChatExporter.Core.Utils.Extensions;
@@ -8,4 +12,13 @@ public static class HttpExtensions
headers.TryGetValues(name, out var values)
? string.Concat(values)
: null;
public static HttpStatusCode? TryGetStatusCode(this HttpRequestException ex) =>
// This is extremely frail, but there's no other way
Regex
.Match(ex.Message, @": (\d+) \(")
.Groups[1]
.Value
.NullIfWhiteSpace()?
.Pipe(s => (HttpStatusCode) int.Parse(s, CultureInfo.InvariantCulture));
}