#603 return 502 when request cannot be completed

This commit is contained in:
jlukawska 2019-11-22 08:01:02 +01:00
parent f15e3a9acf
commit f35a07a3da
4 changed files with 36 additions and 4 deletions

View File

@ -42,7 +42,7 @@ namespace Ocelot.Responder
if (errors.Any(e => e.Code == OcelotErrorCode.UnableToCompleteRequestError)) if (errors.Any(e => e.Code == OcelotErrorCode.UnableToCompleteRequestError))
{ {
return 500; return 502;
} }
return 404; return 404;

View File

@ -18,6 +18,38 @@
_steps = new Steps(); _steps = new Steps();
} }
[Fact]
public void should_return_bad_gateway_error_if_downstream_service_doesnt_respond()
{
var configuration = new FileConfiguration
{
ReRoutes = new List<FileReRoute>
{
new FileReRoute
{
DownstreamPathTemplate = "/",
UpstreamPathTemplate = "/",
UpstreamHttpMethod = new List<string> { "Get" },
DownstreamHostAndPorts = new List<FileHostAndPort>
{
new FileHostAndPort
{
Host = "localhost",
Port = 53876,
},
},
DownstreamScheme = "http",
},
},
};
this.Given(x => _steps.GivenThereIsAConfiguration(configuration))
.And(x => _steps.GivenOcelotIsRunning())
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
.Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.BadGateway))
.BDDfy();
}
[Fact] [Fact]
public void should_return_internal_server_error_if_downstream_service_returns_internal_server_error() public void should_return_internal_server_error_if_downstream_service_returns_internal_server_error()
{ {

View File

@ -89,7 +89,7 @@ namespace Ocelot.AcceptanceTests
.And(x => _steps.GivenThereIsAConfiguration(configuration)) .And(x => _steps.GivenThereIsAConfiguration(configuration))
.And(x => _steps.GivenOcelotIsRunning()) .And(x => _steps.GivenOcelotIsRunning())
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/")) .When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
.Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.InternalServerError)) .Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.BadGateway))
.BDDfy(); .BDDfy();
} }

View File

@ -47,9 +47,9 @@ namespace Ocelot.UnitTests.Responder
[Theory] [Theory]
[InlineData(OcelotErrorCode.UnableToCompleteRequestError)] [InlineData(OcelotErrorCode.UnableToCompleteRequestError)]
public void should_return_internal_server_error(OcelotErrorCode errorCode) public void should_return_bad_gateway_error(OcelotErrorCode errorCode)
{ {
ShouldMapErrorToStatusCode(errorCode, HttpStatusCode.InternalServerError); ShouldMapErrorToStatusCode(errorCode, HttpStatusCode.BadGateway);
} }
[Theory] [Theory]