From c3a63d71e446351f9164acbb9efa65e45feeda27 Mon Sep 17 00:00:00 2001 From: Nick Muller Date: Sat, 23 Jul 2016 23:35:23 +0200 Subject: [PATCH] Added empty json container if server response is empty. This fixes a possible NullReferenceException, which at least occurred in every call to SaveAlbums(). --- SpotifyAPI/Web/SpotifyWebClient.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/SpotifyAPI/Web/SpotifyWebClient.cs b/SpotifyAPI/Web/SpotifyWebClient.cs index 5b43fd84..2375f05a 100644 --- a/SpotifyAPI/Web/SpotifyWebClient.cs +++ b/SpotifyAPI/Web/SpotifyWebClient.cs @@ -37,7 +37,7 @@ namespace SpotifyAPI.Web try { Tuple raw = DownloadRaw(url); - response = new Tuple(raw.Item1, _encoding.GetString(raw.Item2)); + response = new Tuple(raw.Item1, raw.Item2.Length > 0 ? _encoding.GetString(raw.Item2) : "{}"); } catch (WebException e) { @@ -58,7 +58,7 @@ namespace SpotifyAPI.Web try { Tuple raw = await DownloadRawAsync(url); - response = new Tuple(raw.Item1, _encoding.GetString(raw.Item2)); + response = new Tuple(raw.Item1, raw.Item2.Length > 0 ? _encoding.GetString(raw.Item2) : "{}"); } catch (WebException e) { @@ -118,7 +118,7 @@ namespace SpotifyAPI.Web try { Tuple data = UploadRaw(url, body, method); - response = new Tuple(data.Item1, _encoding.GetString(data.Item2)); + response = new Tuple(data.Item1, data.Item2.Length > 0 ? _encoding.GetString(data.Item2) : "{}"); } catch (WebException e) { @@ -139,7 +139,7 @@ namespace SpotifyAPI.Web try { Tuple data = await UploadRawAsync(url, body, method); - response = new Tuple(data.Item1, _encoding.GetString(data.Item2)); + response = new Tuple(data.Item1, data.Item2.Length > 0 ? _encoding.GetString(data.Item2) : "{}"); } catch (WebException e) {