pull/980/head
Tyrrrz 2 years ago
parent 49c4b12512
commit e5d5f1c85f

@ -56,7 +56,7 @@ public class DiscordClient
// This may add an unnecessary delay in case the user doesn't intend to
// make any more requests, but implementing a smarter solution would
// require properly keeping track of Discord's global/per-route/per-resource
// rate limits and that's not worth the effort.
// rate limits and that's just way too much effort.
var remainingRequestCount = response
.Headers
.TryGetValue("X-RateLimit-Remaining")?

@ -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));
}

@ -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));
}
Loading…
Cancel
Save