From d2432cf7f704fadd5baaaef2c215ca778cdd4f1d Mon Sep 17 00:00:00 2001 From: Dilsy99 <38723855+Dilsy99@users.noreply.github.com> Date: Mon, 30 Apr 2018 10:23:02 +0100 Subject: [PATCH] Develop (#338) * #330 Fix and issue with the httpclient being cached on the url but not taking the http verb into accont. This caused an issue because if the same url but different verbs had handlers, the incorrect handler would be called * Amend so that UnableToCompleteRequestError returns 500 rather than 404. This error occur when a delegate handler throws an exception * Fix test that broke because of the change from 404 to 500 when delegate changes --- src/Ocelot/Responder/ErrorsToHttpStatusCodeMapper.cs | 5 +++++ test/Ocelot.AcceptanceTests/SslTests.cs | 2 +- .../Responder/ErrorsToHttpStatusCodeMapperTests.cs | 8 +++++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Ocelot/Responder/ErrorsToHttpStatusCodeMapper.cs b/src/Ocelot/Responder/ErrorsToHttpStatusCodeMapper.cs index 61d27de0..a417f2f9 100644 --- a/src/Ocelot/Responder/ErrorsToHttpStatusCodeMapper.cs +++ b/src/Ocelot/Responder/ErrorsToHttpStatusCodeMapper.cs @@ -32,6 +32,11 @@ namespace Ocelot.Responder return 404; } + if (errors.Any(e => e.Code == OcelotErrorCode.UnableToCompleteRequestError)) + { + return 500; + } + return 404; } } diff --git a/test/Ocelot.AcceptanceTests/SslTests.cs b/test/Ocelot.AcceptanceTests/SslTests.cs index 309bbf28..be753b46 100644 --- a/test/Ocelot.AcceptanceTests/SslTests.cs +++ b/test/Ocelot.AcceptanceTests/SslTests.cs @@ -92,7 +92,7 @@ namespace Ocelot.AcceptanceTests .And(x => _steps.GivenThereIsAConfiguration(configuration)) .And(x => _steps.GivenOcelotIsRunning()) .When(x => _steps.WhenIGetUrlOnTheApiGateway("/")) - .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.NotFound)) + .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.InternalServerError)) .BDDfy(); } diff --git a/test/Ocelot.UnitTests/Responder/ErrorsToHttpStatusCodeMapperTests.cs b/test/Ocelot.UnitTests/Responder/ErrorsToHttpStatusCodeMapperTests.cs index 27417907..fbc17868 100644 --- a/test/Ocelot.UnitTests/Responder/ErrorsToHttpStatusCodeMapperTests.cs +++ b/test/Ocelot.UnitTests/Responder/ErrorsToHttpStatusCodeMapperTests.cs @@ -45,6 +45,13 @@ namespace Ocelot.UnitTests.Responder ShouldMapErrorToStatusCode(errorCode, HttpStatusCode.ServiceUnavailable); } + [Theory] + [InlineData(OcelotErrorCode.UnableToCompleteRequestError)] + public void should_return_internal_server_error(OcelotErrorCode errorCode) + { + ShouldMapErrorToStatusCode(errorCode, HttpStatusCode.InternalServerError); + } + [Theory] [InlineData(OcelotErrorCode.CannotAddDataError)] [InlineData(OcelotErrorCode.CannotFindDataError)] @@ -60,7 +67,6 @@ namespace Ocelot.UnitTests.Responder [InlineData(OcelotErrorCode.RateLimitOptionsError)] [InlineData(OcelotErrorCode.ServicesAreEmptyError)] [InlineData(OcelotErrorCode.ServicesAreNullError)] - [InlineData(OcelotErrorCode.UnableToCompleteRequestError)] [InlineData(OcelotErrorCode.UnableToCreateAuthenticationHandlerError)] [InlineData(OcelotErrorCode.UnableToFindDownstreamRouteError)] [InlineData(OcelotErrorCode.UnableToFindLoadBalancerError)]