Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DigitalOcean.API/DigitalOcean.API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<TargetFramework>net6.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>vevix</Authors>
<Version>5.2.0</Version>
<Version>5.3.0-rc2</Version>
<Description>.NET wrapper of the DigitalOcean API</Description>
<Copyright>2019</Copyright>
<PackageId>DigitalOcean.API</PackageId>
Expand Down
14 changes: 11 additions & 3 deletions DigitalOcean.API/Extensions/RestSharpExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public static Task<IReadOnlyList<byte>> ToByteArrayAsync(this Task<RestResponse>

private static RestResponse ThrowIfException(this RestResponse response) {
if (response.ErrorException != null) {
throw new Exception("There was an an exception thrown during the request.",
throw new Exception("There was an an exception thrown during the request. " +
$"Resource: {response.Request.Resource}. Status: {response.StatusCode}. Body: {response.Content}",
response.ErrorException);
}

Expand All @@ -50,8 +51,15 @@ private static Task<RestResponse> GetResponseContentAsync(IRestClient theClient,

public static T Deserialize<T>(this RestResponse response) {
response.Request.OnBeforeDeserialization(response);
var parsedJson = (JObject)JsonConvert.DeserializeObject(response.Content);
return JsonDeserializationHelper.DeserializeWithRootElementName<T>(parsedJson, response.Request.RootElement);
try {
var parsedJson = (JObject)JsonConvert.DeserializeObject(response.Content);
return JsonDeserializationHelper.DeserializeWithRootElementName<T>(parsedJson, response.Request.RootElement);
}
catch (Exception ex) {
throw new Exception($"Failed deserializing response. " +
$"Resource: {response.Request.Resource}. Status: {response.StatusCode}. Body: {response.Content}",
ex);
}
}
}
}