diff --git a/SpotifyAPI/Web/Models/BasicModel.cs b/SpotifyAPI/Web/Models/BasicModel.cs index 7275f9ac..d6f54697 100644 --- a/SpotifyAPI/Web/Models/BasicModel.cs +++ b/SpotifyAPI/Web/Models/BasicModel.cs @@ -9,14 +9,16 @@ namespace SpotifyAPI.Web.Models [JsonProperty("error")] public Error Error { get; set; } - private WebHeaderCollection _headers; + private ResponseInfo _info; public bool HasError() => Error != null; - internal void AddResponseInfo(ResponseInfo info) => _headers = info.Headers; + internal void AddResponseInfo(ResponseInfo info) => _info = info; - public string Header(string key) => _headers?.Get(key); + public string Header(string key) => _info.Headers?.Get(key); - public WebHeaderCollection Headers() => _headers; + public WebHeaderCollection Headers() => _info.Headers; + + public HttpStatusCode StatusCode() => _info.StatusCode; } } \ No newline at end of file diff --git a/SpotifyAPI/Web/Models/ResponseInfo.cs b/SpotifyAPI/Web/Models/ResponseInfo.cs index ffc94777..1a8a12c2 100644 --- a/SpotifyAPI/Web/Models/ResponseInfo.cs +++ b/SpotifyAPI/Web/Models/ResponseInfo.cs @@ -6,6 +6,8 @@ namespace SpotifyAPI.Web.Models { public WebHeaderCollection Headers { get; set; } + public HttpStatusCode StatusCode { get; set; } + public static readonly ResponseInfo Empty = new ResponseInfo(); } } \ No newline at end of file diff --git a/SpotifyAPI/Web/SpotifyWebClient.cs b/SpotifyAPI/Web/SpotifyWebClient.cs index 24077b5b..c0b418f8 100644 --- a/SpotifyAPI/Web/SpotifyWebClient.cs +++ b/SpotifyAPI/Web/SpotifyWebClient.cs @@ -43,8 +43,9 @@ namespace SpotifyAPI.Web } using (HttpResponseMessage response = Task.Run(() => client.GetAsync(url)).Result) { - return new Tuple(new ResponseInfo() + return new Tuple(new ResponseInfo { + StatusCode = response.StatusCode, Headers = ConvertHeaders(response.Headers) }, Task.Run(() => response.Content.ReadAsByteArrayAsync()).Result); } @@ -64,8 +65,9 @@ namespace SpotifyAPI.Web } using (HttpResponseMessage response = await client.GetAsync(url).ConfigureAwait(false)) { - return new Tuple(new ResponseInfo() + return new Tuple(new ResponseInfo { + StatusCode = response.StatusCode, Headers = ConvertHeaders(response.Headers) }, await response.Content.ReadAsByteArrayAsync()); } @@ -116,6 +118,7 @@ namespace SpotifyAPI.Web { return new Tuple(new ResponseInfo { + StatusCode = response.StatusCode, Headers = ConvertHeaders(response.Headers) }, Task.Run(() => response.Content.ReadAsByteArrayAsync()).Result); } @@ -142,6 +145,7 @@ namespace SpotifyAPI.Web { return new Tuple(new ResponseInfo { + StatusCode = response.StatusCode, Headers = ConvertHeaders(response.Headers) }, await response.Content.ReadAsByteArrayAsync()); }