Browse Source

specify reason why exception is thrown despite regex match

pull/1260/head
Chris Johnston 6 years ago
parent
commit
fdc268c39a
1 changed files with 5 additions and 4 deletions
  1. +5
    -4
      src/Discord.Net.Webhook/DiscordWebhookClient.cs

+ 5
- 4
src/Discord.Net.Webhook/DiscordWebhookClient.cs View File

@@ -64,18 +64,19 @@ namespace Discord.Webhook
"The given webhook Url cannot be null or whitespace."); "The given webhook Url cannot be null or whitespace.");


// thrown when groups are not populated/valid, or when there is no match // thrown when groups are not populated/valid, or when there is no match
ArgumentException ex()
=> new ArgumentException(paramName: nameof(webhookUrl), message: "The given webhook Url was not in a valid format.");
ArgumentException ex(string reason = null)
=> new ArgumentException(paramName: nameof(webhookUrl), message:
$"The given webhook Url was not in a valid format. {reason}");
var match = WebhookUrlRegex.Match(webhookUrl); var match = WebhookUrlRegex.Match(webhookUrl);
if (match != null) if (match != null)
{ {
// ensure that the first group is a ulong, set the _webhookId // ensure that the first group is a ulong, set the _webhookId
// 0th group is always the entire match, so start at index 1 // 0th group is always the entire match, so start at index 1
if (!(match.Groups[1].Success && ulong.TryParse(match.Groups[1].Value, out _webhookId))) if (!(match.Groups[1].Success && ulong.TryParse(match.Groups[1].Value, out _webhookId)))
throw ex();
throw ex("The webhook Id could not be parsed.");


if (!match.Groups[2].Success) if (!match.Groups[2].Success)
throw ex();
throw ex("The webhook token could not be parsed.");


ApiClient.LoginAsync(TokenType.Webhook, match.Groups[2].Value).GetAwaiter().GetResult(); ApiClient.LoginAsync(TokenType.Webhook, match.Groups[2].Value).GetAwaiter().GetResult();
Webhook = WebhookClientHelper.GetWebhookAsync(this, _webhookId).GetAwaiter().GetResult(); Webhook = WebhookClientHelper.GetWebhookAsync(this, _webhookId).GetAwaiter().GetResult();


Loading…
Cancel
Save