Skip to content

Commit a5c584a

Browse files
author
Jonas Dellinger
authored
Merge pull request JohnnyCrazy#94 from nphmuller/NullRefInApiCall
Added null check to fix NullReferenceException in api call.
2 parents 0b259c3 + c3a63d7 commit a5c584a

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

‎SpotifyAPI/Web/SpotifyWebClient.cs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public Tuple<ResponseInfo, string> Download(string url)
3737
try
3838
{
3939
Tuple<ResponseInfo, byte[]> raw = DownloadRaw(url);
40-
response = new Tuple<ResponseInfo, string>(raw.Item1, _encoding.GetString(raw.Item2));
40+
response = new Tuple<ResponseInfo, string>(raw.Item1, raw.Item2.Length > 0 ? _encoding.GetString(raw.Item2) : "{}");
4141
}
4242
catch (WebException e)
4343
{
@@ -58,7 +58,7 @@ public async Task<Tuple<ResponseInfo, string>> DownloadAsync(string url)
5858
try
5959
{
6060
Tuple<ResponseInfo, byte[]> raw = await DownloadRawAsync(url);
61-
response = new Tuple<ResponseInfo, string>(raw.Item1, _encoding.GetString(raw.Item2));
61+
response = new Tuple<ResponseInfo, string>(raw.Item1, raw.Item2.Length > 0 ? _encoding.GetString(raw.Item2) : "{}");
6262
}
6363
catch (WebException e)
6464
{
@@ -118,7 +118,7 @@ public Tuple<ResponseInfo, string> Upload(string url, string body, string method
118118
try
119119
{
120120
Tuple<ResponseInfo, byte[]> data = UploadRaw(url, body, method);
121-
response = new Tuple<ResponseInfo, string>(data.Item1, _encoding.GetString(data.Item2));
121+
response = new Tuple<ResponseInfo, string>(data.Item1, data.Item2.Length > 0 ? _encoding.GetString(data.Item2) : "{}");
122122
}
123123
catch (WebException e)
124124
{
@@ -139,7 +139,7 @@ public async Task<Tuple<ResponseInfo, string>> UploadAsync(string url, string bo
139139
try
140140
{
141141
Tuple<ResponseInfo, byte[]> data = await UploadRawAsync(url, body, method);
142-
response = new Tuple<ResponseInfo, string>(data.Item1, _encoding.GetString(data.Item2));
142+
response = new Tuple<ResponseInfo, string>(data.Item1, data.Item2.Length > 0 ? _encoding.GetString(data.Item2) : "{}");
143143
}
144144
catch (WebException e)
145145
{

0 commit comments

Comments
 (0)