Skip to content

Commit 2771499

Browse files
authored
Merge pull request #188 from L-Naej/develop
Fix: Handle HTTP NO CONTENT status code (204) to prevent null reference exceptions in HttpBase.cs
2 parents a3bb763 + 2eb2cfc commit 2771499

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/Proyecto26.RestClient/Helpers/HttpBase.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ namespace Proyecto26
88
{
99
public static class HttpBase
1010
{
11+
public static int HTTP_NO_CONTENT = 204;
12+
1113
public static IEnumerator CreateRequestAndRetry(RequestHelper options, Action<RequestException, ResponseHelper> callback)
1214
{
1315

@@ -118,7 +120,7 @@ public static IEnumerator DefaultUnityWebRequest<TResponse>(RequestHelper option
118120
var body = default(TResponse);
119121
try
120122
{
121-
if (err == null && res.Data != null && options.ParseResponseBody)
123+
if (err == null && res.StatusCode != HTTP_NO_CONTENT && res.Data != null && options.ParseResponseBody)
122124
body = JsonUtility.FromJson<TResponse>(res.Text);
123125
}
124126
catch (Exception error)
@@ -139,7 +141,7 @@ public static IEnumerator DefaultUnityWebRequest<TResponse>(RequestHelper option
139141
var body = default(TResponse[]);
140142
try
141143
{
142-
if (err == null && res.Data != null && options.ParseResponseBody)
144+
if (err == null && res.StatusCode != HTTP_NO_CONTENT && res.Data != null && options.ParseResponseBody)
143145
body = JsonHelper.ArrayFromJson<TResponse>(res.Text);
144146
}
145147
catch (Exception error)

0 commit comments

Comments
 (0)