Skip to content

Commit

Permalink
fix: possible nre fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Lulalaby committed Jan 2, 2024
1 parent f37488f commit e0a1dad
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
3 changes: 1 addition & 2 deletions DisCatSharp/Net/Rest/RestClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -526,8 +526,7 @@ private async Task ExecuteRequestAsync(BaseRestRequest request, RateLimitBucket?
var response = new RestResponse();
try
{
if (this._disposed)
return;
ObjectDisposedException.ThrowIf(this._disposed, this);

res = await this.HttpClient.SendAsync(req, HttpCompletionOption.ResponseContentRead, CancellationToken.None).ConfigureAwait(false);

Expand Down
2 changes: 1 addition & 1 deletion DisCatSharp/Net/Rest/RestResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public sealed class RestResponse
/// <summary>
/// Gets the contents of the response sent by the remote party.
/// </summary>
public string Response { get; internal set; } = null!;
public string Response { get; internal set; }

/// <summary>
/// Initializes a new instance of the <see cref="RestResponse"/> class.
Expand Down
14 changes: 10 additions & 4 deletions DisCatSharp/Net/Serialization/DiscordJson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static string SerializeObject(object value)
/// <typeparam name="T">The type</typeparam>
/// <param name="json">The received json.</param>
/// <param name="discord">The discord client.</param>
public static T DeserializeObject<T>(string json, BaseDiscordClient? discord) where T : ObservableApiObject
public static T DeserializeObject<T>(string? json, BaseDiscordClient? discord) where T : ObservableApiObject
=> DeserializeObjectInternal<T>(json, discord);

/// <summary>
Expand All @@ -50,7 +50,7 @@ public static T DeserializeObject<T>(string json, BaseDiscordClient? discord) wh
/// <typeparam name="T">The enumerable type.</typeparam>
/// <param name="json">The received json.</param>
/// <param name="discord">The discord client.</param>
public static T DeserializeIEnumerableObject<T>(string json, BaseDiscordClient? discord) where T : IEnumerable<ObservableApiObject>
public static T DeserializeIEnumerableObject<T>(string? json, BaseDiscordClient? discord) where T : IEnumerable<ObservableApiObject>
=> DeserializeIEnumerableObjectInternal<T>(json, discord);

/// <summary>Populates an object with the values from a JSON node.</summary>
Expand Down Expand Up @@ -95,8 +95,11 @@ private static string SerializeObjectInternal(object value, Type type, JsonSeria
/// <typeparam name="T">The type</typeparam>
/// <param name="json">The received json.</param>
/// <param name="discord">The discord client.</param>
private static T DeserializeObjectInternal<T>(string json, BaseDiscordClient? discord) where T : ObservableApiObject
private static T DeserializeObjectInternal<T>(string? json, BaseDiscordClient? discord) where T : ObservableApiObject
{
if (string.IsNullOrEmpty(json))
return default;

var obj = JsonConvert.DeserializeObject<T>(json, new JsonSerializerSettings()
{
ContractResolver = new OptionalJsonContractResolver()
Expand Down Expand Up @@ -168,8 +171,11 @@ private static T DeserializeObjectInternal<T>(string json, BaseDiscordClient? di
/// <typeparam name="T">The enumerable type.</typeparam>
/// <param name="json">The received json.</param>
/// <param name="discord">The discord client.</param>
private static T DeserializeIEnumerableObjectInternal<T>(string json, BaseDiscordClient? discord) where T : IEnumerable<ObservableApiObject>
private static T DeserializeIEnumerableObjectInternal<T>(string? json, BaseDiscordClient? discord) where T : IEnumerable<ObservableApiObject>
{
if (string.IsNullOrEmpty(json))
return default;

var obj = JsonConvert.DeserializeObject<T>(json, new JsonSerializerSettings()
{
ContractResolver = new OptionalJsonContractResolver()
Expand Down

0 comments on commit e0a1dad

Please sign in to comment.