Skip to content

Commit

Permalink
chore: append a debug breakpoint we can use during development
Browse files Browse the repository at this point in the history
  • Loading branch information
Lulalaby committed Jan 3, 2024
1 parent 9718f58 commit 3335871
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
23 changes: 14 additions & 9 deletions DisCatSharp/Net/Rest/DiscordApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,15 @@ private void PopulateMessage(TransportUser author, DiscordMessage ret)
/// <param name="headers">The headers.</param>
/// <param name="payload">The payload.</param>
/// <param name="ratelimitWaitOverride">The ratelimit wait override.</param>
internal Task<RestResponse> DoRequestAsync(BaseDiscordClient client, RateLimitBucket bucket, Uri url, RestRequestMethod method, string route, IReadOnlyDictionary<string, string>? headers = null, string? payload = null, double? ratelimitWaitOverride = null)
/// <param name="targetDebug">Enables a possible breakpoint in the rest client for debugging purposes.</param>
internal Task<RestResponse> DoRequestAsync(BaseDiscordClient client, RateLimitBucket bucket, Uri url, RestRequestMethod method, string route, IReadOnlyDictionary<string, string>? 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();
}
Expand All @@ -225,11 +226,12 @@ internal Task<RestResponse> DoRequestAsync(BaseDiscordClient client, RateLimitBu
/// <param name="headers">The headers.</param>
/// <param name="formData">The form data.</param>
/// <param name="ratelimitWaitOverride">The ratelimit wait override.</param>
internal Task<RestResponse> DoFormRequestAsync(DiscordOAuth2Client client, RateLimitBucket bucket, Uri url, RestRequestMethod method, string route, Dictionary<string, string> formData, Dictionary<string, string>? headers = null, double? ratelimitWaitOverride = null)
/// <param name="targetDebug">Enables a possible breakpoint in the rest client for debugging purposes.</param>
internal Task<RestResponse> DoFormRequestAsync(DiscordOAuth2Client client, RateLimitBucket bucket, Uri url, RestRequestMethod method, string route, Dictionary<string, string> formData, Dictionary<string, string>? 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();
}
Expand All @@ -248,6 +250,7 @@ internal Task<RestResponse> DoFormRequestAsync(DiscordOAuth2Client client, RateL
/// <param name="headers">The headers.</param>
/// <param name="file">The file.</param>
/// <param name="ratelimitWaitOverride">The ratelimit wait override.</param>
/// <param name="targetDebug">Enables a possible breakpoint in the rest client for debugging purposes.</param>
private Task<RestResponse> DoStickerMultipartAsync(
BaseDiscordClient client,
RateLimitBucket bucket,
Expand All @@ -259,15 +262,16 @@ private Task<RestResponse> DoStickerMultipartAsync(
string? description = null,
IReadOnlyDictionary<string, string>? 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();
}
Expand All @@ -284,6 +288,7 @@ private Task<RestResponse> DoStickerMultipartAsync(
/// <param name="values">The values.</param>
/// <param name="files">The files.</param>
/// <param name="ratelimitWaitOverride">The ratelimit wait override.</param>
/// <param name="targetDebug">Enables a possible breakpoint in the rest client for debugging purposes.</param>
private Task<RestResponse> DoMultipartAsync(
BaseDiscordClient client,
RateLimitBucket bucket,
Expand All @@ -302,7 +307,7 @@ private Task<RestResponse> 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();
}
Expand Down
10 changes: 7 additions & 3 deletions DisCatSharp/Net/Rest/RestClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,15 +244,17 @@ public RateLimitBucket GetBucket(RestRequestMethod method, string route, object
/// Executes the request.
/// </summary>
/// <param name="request">The request to be executed.</param>
/// <param name="targetDebug">Enables a possible breakpoint in the rest client for debugging purposes.</param>
public Task ExecuteRequestAsync(BaseRestRequest request, bool targetDebug = false)
=> request is null ? throw new ArgumentNullException(nameof(request)) : this.ExecuteRequestAsync(request, null, null, targetDebug);

/// <summary>
/// Executes the form data request.
/// </summary>
/// <param name="request">The request to be executed.</param>
public Task ExecuteFormRequestAsync(BaseRestRequest request)
=> request is null ? throw new ArgumentNullException(nameof(request)) : this.ExecuteFormRequestAsync(request, null, null);
/// <param name="targetDebug">Enables a possible breakpoint in the rest client for debugging purposes.</param>
public Task ExecuteFormRequestAsync(BaseRestRequest request, bool targetDebug = false)
=> request is null ? throw new ArgumentNullException(nameof(request)) : this.ExecuteFormRequestAsync(request, null, null, targetDebug);

/// <summary>
/// Executes the form data request.
Expand All @@ -261,7 +263,8 @@ public Task ExecuteFormRequestAsync(BaseRestRequest request)
/// <param name="request">The request to be executed.</param>
/// <param name="bucket">The bucket.</param>
/// <param name="ratelimitTcs">The ratelimit task completion source.</param>
private async Task ExecuteFormRequestAsync(BaseRestRequest request, RateLimitBucket? bucket, TaskCompletionSource<bool>? ratelimitTcs)
/// <param name="targetDebug">Enables a possible breakpoint in the rest client for debugging purposes.</param>
private async Task ExecuteFormRequestAsync(BaseRestRequest request, RateLimitBucket? bucket, TaskCompletionSource<bool>? ratelimitTcs, bool targetDebug = false)
{
if (this._disposed)
return;
Expand Down Expand Up @@ -461,6 +464,7 @@ private async Task ExecuteFormRequestAsync(BaseRestRequest request, RateLimitBuc
/// <param name="request">The request to be executed.</param>
/// <param name="bucket">The bucket.</param>
/// <param name="ratelimitTcs">The ratelimit task completion source.</param>
/// <param name="targetDebug">Enables a possible breakpoint in the rest client for debugging purposes.</param>
private async Task ExecuteRequestAsync(BaseRestRequest request, RateLimitBucket? bucket, TaskCompletionSource<bool>? ratelimitTcs, bool targetDebug = false)
{
ObjectDisposedException.ThrowIf(this._disposed, this);
Expand Down

0 comments on commit 3335871

Please sign in to comment.