Skip to content

Commit

Permalink
Crankshaft[BU000005X2NR89] .NET client @ 2018-07-05 10:03:39 UTC
Browse files Browse the repository at this point in the history
  • Loading branch information
Crankshaft Robot committed Jul 5, 2018
1 parent 6c0bbae commit bff7897
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
20 changes: 20 additions & 0 deletions GoCardless.Tests/ErrorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,26 @@ public async Task TrueServerError()
Assert.Fail("Exception was not thrown");
}

[Test]
public async Task HtmlErrorPage()
{
var responseFixture = "fixtures/error_page.html";
mockHttp.EnqueueResponse(502, responseFixture);
try
{
await MakeSomeRequest();
}
catch (ApiException ex)
{
Assert.AreEqual(502, ex.Code);
Assert.AreEqual(ApiErrorType.GOCARDLESS, ex.Type);
Assert.AreEqual("Something went wrong with this request. Please check the ResponseMessage property.", ex.Message);
Assert.AreEqual("<!DOCTYPE html>\n<html>\n <head>\n <title>This is an HTML error page, like one returned by Cloudflare</title>\n </head>\n</html>\n", ex.ResponseMessage.Content.ReadAsStringAsync().Result);
return;
}
Assert.Fail("Exception was not thrown");
}

[Test]
public async Task IdempotencyConflictsAreHandledAutomatically()
{
Expand Down
5 changes: 4 additions & 1 deletion GoCardless.Tests/GoCardless.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
<None Update="fixtures\client\list_mandates_page_2.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="fixtures\error_page.html">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="fixtures\idempotent_creation_conflict.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down Expand Up @@ -97,4 +100,4 @@
</None>
</ItemGroup>

</Project>
</Project>
6 changes: 6 additions & 0 deletions GoCardless.Tests/fixtures/error_page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<!DOCTYPE html>
<html>
<head>
<title>This is an HTML error page, like one returned by Cloudflare</title>
</head>
</html>
2 changes: 1 addition & 1 deletion GoCardless/GoCardlessClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ private async Task<T> ExecuteAsyncInner<T>(string method, string path, List<KeyV
throw result.ToException();
}
}
catch (JsonSerializationException)
catch (JsonException)
{
throw new ApiException(new ApiErrorResponse()
{
Expand Down

0 comments on commit bff7897

Please sign in to comment.