diff --git a/GoCardless.Tests/ErrorTests.cs b/GoCardless.Tests/ErrorTests.cs index 5a76a60..bdc4a6e 100644 --- a/GoCardless.Tests/ErrorTests.cs +++ b/GoCardless.Tests/ErrorTests.cs @@ -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("\n\n \n This is an HTML error page, like one returned by Cloudflare\n \n\n", ex.ResponseMessage.Content.ReadAsStringAsync().Result); + return; + } + Assert.Fail("Exception was not thrown"); + } + [Test] public async Task IdempotencyConflictsAreHandledAutomatically() { diff --git a/GoCardless.Tests/GoCardless.Tests.csproj b/GoCardless.Tests/GoCardless.Tests.csproj index 242c228..34e985f 100644 --- a/GoCardless.Tests/GoCardless.Tests.csproj +++ b/GoCardless.Tests/GoCardless.Tests.csproj @@ -53,6 +53,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest @@ -97,4 +100,4 @@ - \ No newline at end of file + diff --git a/GoCardless.Tests/fixtures/error_page.html b/GoCardless.Tests/fixtures/error_page.html new file mode 100644 index 0000000..5fa7c35 --- /dev/null +++ b/GoCardless.Tests/fixtures/error_page.html @@ -0,0 +1,6 @@ + + + + This is an HTML error page, like one returned by Cloudflare + + diff --git a/GoCardless/GoCardlessClient.cs b/GoCardless/GoCardlessClient.cs index d417e80..a203d31 100644 --- a/GoCardless/GoCardlessClient.cs +++ b/GoCardless/GoCardlessClient.cs @@ -186,7 +186,7 @@ private async Task ExecuteAsyncInner(string method, string path, List