Skip to content

Commit

Permalink
Merge pull request #38 from aspriddell/add-staus-code-to-exception
Browse files Browse the repository at this point in the history
use system throw for success code check
  • Loading branch information
aspriddell authored Nov 19, 2020
2 parents 2f18728 + 0de41e6 commit e8c90b3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@ namespace DragonFruit.Common.Data.Tests.Files.Objects
/// <summary>
/// Simple file download request with a path and a destination
/// </summary>
public class FileDownloadRequest : ApiFileRequest
internal sealed class FileDownloadRequest : ApiFileRequest
{
public FileDownloadRequest()
{
if (System.IO.File.Exists(Destination))
{
System.IO.File.Delete(Destination);
}
}

public override string Path => "https://github.com/ppy/osu/archive/2020.327.0.zip";

public override string Destination => System.IO.Path.Combine(System.IO.Path.GetTempPath(), "file.zip");
Expand Down
5 changes: 1 addition & 4 deletions DragonFruit.Common.Data/ApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -350,10 +350,7 @@ protected T InternalPerform<T>(HttpRequestMessage request, Func<HttpResponseMess
/// </summary>
protected virtual T ValidateAndProcess<T>(HttpResponseMessage response, HttpRequestMessage request) where T : class
{
if (!response.IsSuccessStatusCode)
{
throw new HttpRequestException($"Response was unsuccessful ({response.StatusCode})");
}
response.EnsureSuccessStatusCode();

using var stream = response.Content.ReadAsStreamAsync().Result;
return Serializer.Deserialize<T>(stream);
Expand Down

0 comments on commit e8c90b3

Please sign in to comment.