Browse Source

Fix NRE on http error handling (#1970)

In some cases, the code is not able to deserialize API.DiscordError, but
it attempts to use its message to throw an exception. This change uses
null as the exception reason in that case.
tags/3.0.0
Adam Gauthier GitHub 3 years ago
parent
commit
52e2019990
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 10 deletions
  1. +13
    -10
      src/Discord.Net.Rest/Net/Queue/RequestQueueBucket.cs

+ 13
- 10
src/Discord.Net.Rest/Net/Queue/RequestQueueBucket.cs View File

@@ -1,6 +1,4 @@
using Discord.API;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
#if DEBUG_LIMITS
using System.Diagnostics;
@@ -106,17 +104,22 @@ namespace Discord.Net.Queue
{
try
{
using (var reader = new StreamReader(response.Stream))
using (var jsonReader = new JsonTextReader(reader))
{
error = Discord.Rest.DiscordRestClient.Serializer.Deserialize<API.DiscordError>(jsonReader);
}
using var reader = new StreamReader(response.Stream);
using var jsonReader = new JsonTextReader(reader);

error = Discord.Rest.DiscordRestClient.Serializer.Deserialize<API.DiscordError>(jsonReader);
}
catch { }
}
throw new HttpException(response.StatusCode, request, error?.Code, error.Message, error.Errors.IsSpecified
? error.Errors.Value.Select(x => new DiscordJsonError(x.Name.GetValueOrDefault("root"), x.Errors.Select(y => new DiscordError(y.Code, y.Message)).ToArray())).ToArray()
: null);
throw new HttpException(
response.StatusCode,
request,
error?.Code,
error?.Message,
error?.Errors.IsSpecified == true ?
error.Errors.Value.Select(x => new DiscordJsonError(x.Name.GetValueOrDefault("root"), x.Errors.Select(y => new DiscordError(y.Code, y.Message)).ToArray())).ToArray() :
null
);
}
}
else


Loading…
Cancel
Save