Browse Source

fix: Check error 404 and return null for GetBanAsync (#1614)

tags/2.3.0
Paulo GitHub 4 years ago
parent
commit
ae9fff6380
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 3 deletions
  1. +6
    -2
      src/Discord.Net.Rest/DiscordRestApiClient.cs
  2. +1
    -1
      src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs

+ 6
- 2
src/Discord.Net.Rest/DiscordRestApiClient.cs View File

@@ -874,8 +874,12 @@ namespace Discord.API
Preconditions.NotEqual(guildId, 0, nameof(guildId));
options = RequestOptions.CreateOrClone(options);

var ids = new BucketIds(guildId: guildId);
return await SendAsync<Ban>("GET", () => $"guilds/{guildId}/bans/{userId}", ids, options: options).ConfigureAwait(false);
try
{
var ids = new BucketIds(guildId: guildId);
return await SendAsync<Ban>("GET", () => $"guilds/{guildId}/bans/{userId}", ids, options: options).ConfigureAwait(false);
}
catch (HttpException ex) when (ex.HttpCode == HttpStatusCode.NotFound) { return null; }
}
/// <exception cref="ArgumentException">
/// <paramref name="guildId"/> and <paramref name="userId"/> must not be equal to zero.


+ 1
- 1
src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs View File

@@ -132,7 +132,7 @@ namespace Discord.Rest
public static async Task<RestBan> GetBanAsync(IGuild guild, BaseDiscordClient client, ulong userId, RequestOptions options)
{
var model = await client.ApiClient.GetGuildBanAsync(guild.Id, userId, options).ConfigureAwait(false);
return RestBan.Create(client, model);
return model == null ? null : RestBan.Create(client, model);
}

public static async Task AddBanAsync(IGuild guild, BaseDiscordClient client,


Loading…
Cancel
Save