Skip to content

Commit

Permalink
Merge pull request #188 from L-Naej/develop
Browse files Browse the repository at this point in the history
Fix: Handle HTTP NO CONTENT status code (204) to prevent null reference exceptions in HttpBase.cs
  • Loading branch information
jdnichollsc authored Dec 9, 2021
2 parents f5430ef + c4d3841 commit 41ee187
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Proyecto26.RestClient/Helpers/HttpBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ namespace Proyecto26
{
public static class HttpBase
{
public static int HTTP_NO_CONTENT = 204;

public static IEnumerator CreateRequestAndRetry(RequestHelper options, Action<RequestException, ResponseHelper> callback)
{

Expand Down Expand Up @@ -118,7 +120,7 @@ public static IEnumerator DefaultUnityWebRequest<TResponse>(RequestHelper option
var body = default(TResponse);
try
{
if (err == null && res.Data != null && options.ParseResponseBody)
if (err == null && res.StatusCode != HTTP_NO_CONTENT && res.Data != null && options.ParseResponseBody)
body = JsonUtility.FromJson<TResponse>(res.Text);
}
catch (Exception error)
Expand All @@ -139,7 +141,7 @@ public static IEnumerator DefaultUnityWebRequest<TResponse>(RequestHelper option
var body = default(TResponse[]);
try
{
if (err == null && res.Data != null && options.ParseResponseBody)
if (err == null && res.StatusCode != HTTP_NO_CONTENT && res.Data != null && options.ParseResponseBody)
body = JsonHelper.ArrayFromJson<TResponse>(res.Text);
}
catch (Exception error)
Expand Down

0 comments on commit 41ee187

Please sign in to comment.