From 1f17de5ae68b40c1c09e5b8ded973fc67fc82828 Mon Sep 17 00:00:00 2001 From: RogueException Date: Sun, 27 Dec 2015 15:34:47 -0400 Subject: [PATCH] GetInvite returns null if not found --- src/Discord.Net/DiscordClient.cs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Discord.Net/DiscordClient.cs b/src/Discord.Net/DiscordClient.cs index e4b0699aa..ecfa0f402 100644 --- a/src/Discord.Net/DiscordClient.cs +++ b/src/Discord.Net/DiscordClient.cs @@ -10,6 +10,7 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.IO; using System.Linq; +using System.Net; using System.Security.Cryptography; using System.Text; using System.Threading; @@ -373,6 +374,7 @@ namespace Discord #region Invites /// Gets more info about the provided invite code. /// Supported formats: inviteCode, xkcdCode, https://discord.gg/inviteCode, https://discord.gg/xkcdCode + /// The invite object if found, null if not. public async Task GetInvite(string inviteIdOrXkcd) { if (inviteIdOrXkcd == null) throw new ArgumentNullException(nameof(inviteIdOrXkcd)); @@ -385,10 +387,17 @@ namespace Discord if (index >= 0) inviteIdOrXkcd = inviteIdOrXkcd.Substring(index + 1); - var response = await ClientAPI.Send(new GetInviteRequest(inviteIdOrXkcd)).ConfigureAwait(false); - var invite = new Invite(this, response.Code, response.XkcdPass); - invite.Update(response); - return invite; + try + { + var response = await ClientAPI.Send(new GetInviteRequest(inviteIdOrXkcd)).ConfigureAwait(false); + var invite = new Invite(this, response.Code, response.XkcdPass); + invite.Update(response); + return invite; + } + catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) + { + return null; + } } #endregion