From 3335871c1bf438d32aa5493fce521408dc43881e Mon Sep 17 00:00:00 2001 From: Lala Sabathil Date: Wed, 3 Jan 2024 22:01:51 +0100 Subject: [PATCH] chore: append a debug breakpoint we can use during development --- DisCatSharp/Net/Rest/DiscordApiClient.cs | 23 ++++++++++++++--------- DisCatSharp/Net/Rest/RestClient.cs | 10 +++++++--- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/DisCatSharp/Net/Rest/DiscordApiClient.cs b/DisCatSharp/Net/Rest/DiscordApiClient.cs index 31563448f9..be814a8276 100644 --- a/DisCatSharp/Net/Rest/DiscordApiClient.cs +++ b/DisCatSharp/Net/Rest/DiscordApiClient.cs @@ -202,14 +202,15 @@ private void PopulateMessage(TransportUser author, DiscordMessage ret) /// The headers. /// The payload. /// The ratelimit wait override. - internal Task DoRequestAsync(BaseDiscordClient client, RateLimitBucket bucket, Uri url, RestRequestMethod method, string route, IReadOnlyDictionary? headers = null, string? payload = null, double? ratelimitWaitOverride = null) + /// Enables a possible breakpoint in the rest client for debugging purposes. + internal Task DoRequestAsync(BaseDiscordClient client, RateLimitBucket bucket, Uri url, RestRequestMethod method, string route, IReadOnlyDictionary? headers = null, string? payload = null, double? ratelimitWaitOverride = null, bool targetDebug = false) { var req = new RestRequest(client, bucket, url, method, route, headers, payload, ratelimitWaitOverride); if (this.Discord is not null) - this.Rest.ExecuteRequestAsync(req).LogTaskFault(this.Discord.Logger, LogLevel.Error, LoggerEvents.RestError, $"Error while executing request. Url: {url.AbsoluteUri}"); + this.Rest.ExecuteRequestAsync(req, targetDebug).LogTaskFault(this.Discord.Logger, LogLevel.Error, LoggerEvents.RestError, $"Error while executing request. Url: {url.AbsoluteUri}"); else - _ = this.Rest.ExecuteRequestAsync(req); + _ = this.Rest.ExecuteRequestAsync(req, targetDebug); return req.WaitForCompletionAsync(); } @@ -225,11 +226,12 @@ internal Task DoRequestAsync(BaseDiscordClient client, RateLimitBu /// The headers. /// The form data. /// The ratelimit wait override. - internal Task DoFormRequestAsync(DiscordOAuth2Client client, RateLimitBucket bucket, Uri url, RestRequestMethod method, string route, Dictionary formData, Dictionary? headers = null, double? ratelimitWaitOverride = null) + /// Enables a possible breakpoint in the rest client for debugging purposes. + internal Task DoFormRequestAsync(DiscordOAuth2Client client, RateLimitBucket bucket, Uri url, RestRequestMethod method, string route, Dictionary formData, Dictionary? headers = null, double? ratelimitWaitOverride = null, bool targetDebug = false) { var req = new RestFormRequest(client, bucket, url, method, route, formData, headers, ratelimitWaitOverride); - this.Rest.ExecuteFormRequestAsync(req).LogTaskFault(this.OAuth2Client.Logger, LogLevel.Error, LoggerEvents.RestError, $"Error while executing request. Url: {url.AbsoluteUri}"); + this.Rest.ExecuteFormRequestAsync(req, targetDebug).LogTaskFault(this.OAuth2Client.Logger, LogLevel.Error, LoggerEvents.RestError, $"Error while executing request. Url: {url.AbsoluteUri}"); return req.WaitForCompletionAsync(); } @@ -248,6 +250,7 @@ internal Task DoFormRequestAsync(DiscordOAuth2Client client, RateL /// The headers. /// The file. /// The ratelimit wait override. + /// Enables a possible breakpoint in the rest client for debugging purposes. private Task DoStickerMultipartAsync( BaseDiscordClient client, RateLimitBucket bucket, @@ -259,15 +262,16 @@ private Task DoStickerMultipartAsync( string? description = null, IReadOnlyDictionary? headers = null, DiscordMessageFile? file = null, - double? ratelimitWaitOverride = null + double? ratelimitWaitOverride = null, + bool targetDebug = false ) { var req = new MultipartStickerWebRequest(client, bucket, url, method, route, name, tags, description, headers, file, ratelimitWaitOverride); if (this.Discord is not null) - this.Rest.ExecuteRequestAsync(req).LogTaskFault(this.Discord.Logger, LogLevel.Error, LoggerEvents.RestError, "Error while executing request"); + this.Rest.ExecuteRequestAsync(req, targetDebug).LogTaskFault(this.Discord.Logger, LogLevel.Error, LoggerEvents.RestError, "Error while executing request"); else - _ = this.Rest.ExecuteRequestAsync(req); + _ = this.Rest.ExecuteRequestAsync(req, targetDebug); return req.WaitForCompletionAsync(); } @@ -284,6 +288,7 @@ private Task DoStickerMultipartAsync( /// The values. /// The files. /// The ratelimit wait override. + /// Enables a possible breakpoint in the rest client for debugging purposes. private Task DoMultipartAsync( BaseDiscordClient client, RateLimitBucket bucket, @@ -302,7 +307,7 @@ private Task DoMultipartAsync( if (this.Discord is not null) this.Rest.ExecuteRequestAsync(req, targetDebug).LogTaskFault(this.Discord.Logger, LogLevel.Error, LoggerEvents.RestError, "Error while executing request"); else - _ = this.Rest.ExecuteRequestAsync(req); + _ = this.Rest.ExecuteRequestAsync(req, targetDebug); return req.WaitForCompletionAsync(); } diff --git a/DisCatSharp/Net/Rest/RestClient.cs b/DisCatSharp/Net/Rest/RestClient.cs index 37ee6d3590..8fb48a3638 100644 --- a/DisCatSharp/Net/Rest/RestClient.cs +++ b/DisCatSharp/Net/Rest/RestClient.cs @@ -244,6 +244,7 @@ public RateLimitBucket GetBucket(RestRequestMethod method, string route, object /// Executes the request. /// /// The request to be executed. + /// Enables a possible breakpoint in the rest client for debugging purposes. public Task ExecuteRequestAsync(BaseRestRequest request, bool targetDebug = false) => request is null ? throw new ArgumentNullException(nameof(request)) : this.ExecuteRequestAsync(request, null, null, targetDebug); @@ -251,8 +252,9 @@ public Task ExecuteRequestAsync(BaseRestRequest request, bool targetDebug = fals /// Executes the form data request. /// /// The request to be executed. - public Task ExecuteFormRequestAsync(BaseRestRequest request) - => request is null ? throw new ArgumentNullException(nameof(request)) : this.ExecuteFormRequestAsync(request, null, null); + /// Enables a possible breakpoint in the rest client for debugging purposes. + public Task ExecuteFormRequestAsync(BaseRestRequest request, bool targetDebug = false) + => request is null ? throw new ArgumentNullException(nameof(request)) : this.ExecuteFormRequestAsync(request, null, null, targetDebug); /// /// Executes the form data request. @@ -261,7 +263,8 @@ public Task ExecuteFormRequestAsync(BaseRestRequest request) /// The request to be executed. /// The bucket. /// The ratelimit task completion source. - private async Task ExecuteFormRequestAsync(BaseRestRequest request, RateLimitBucket? bucket, TaskCompletionSource? ratelimitTcs) + /// Enables a possible breakpoint in the rest client for debugging purposes. + private async Task ExecuteFormRequestAsync(BaseRestRequest request, RateLimitBucket? bucket, TaskCompletionSource? ratelimitTcs, bool targetDebug = false) { if (this._disposed) return; @@ -461,6 +464,7 @@ private async Task ExecuteFormRequestAsync(BaseRestRequest request, RateLimitBuc /// The request to be executed. /// The bucket. /// The ratelimit task completion source. + /// Enables a possible breakpoint in the rest client for debugging purposes. private async Task ExecuteRequestAsync(BaseRestRequest request, RateLimitBucket? bucket, TaskCompletionSource? ratelimitTcs, bool targetDebug = false) { ObjectDisposedException.ThrowIf(this._disposed, this);