Skip to content

Commit f35a07a

Browse files
committed
#603 return 502 when request cannot be completed
1 parent f15e3a9 commit f35a07a

File tree

4 files changed

+36
-4
lines changed

4 files changed

+36
-4
lines changed

src/Ocelot/Responder/ErrorsToHttpStatusCodeMapper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public int Map(List<Error> errors)
4242

4343
if (errors.Any(e => e.Code == OcelotErrorCode.UnableToCompleteRequestError))
4444
{
45-
return 500;
45+
return 502;
4646
}
4747

4848
return 404;

test/Ocelot.AcceptanceTests/ReturnsErrorTests.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,38 @@ public ReturnsErrorTests()
1616
{
1717
_serviceHandler = new ServiceHandler();
1818
_steps = new Steps();
19+
}
20+
21+
[Fact]
22+
public void should_return_bad_gateway_error_if_downstream_service_doesnt_respond()
23+
{
24+
var configuration = new FileConfiguration
25+
{
26+
ReRoutes = new List<FileReRoute>
27+
{
28+
new FileReRoute
29+
{
30+
DownstreamPathTemplate = "/",
31+
UpstreamPathTemplate = "/",
32+
UpstreamHttpMethod = new List<string> { "Get" },
33+
DownstreamHostAndPorts = new List<FileHostAndPort>
34+
{
35+
new FileHostAndPort
36+
{
37+
Host = "localhost",
38+
Port = 53876,
39+
},
40+
},
41+
DownstreamScheme = "http",
42+
},
43+
},
44+
};
45+
46+
this.Given(x => _steps.GivenThereIsAConfiguration(configuration))
47+
.And(x => _steps.GivenOcelotIsRunning())
48+
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
49+
.Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.BadGateway))
50+
.BDDfy();
1951
}
2052

2153
[Fact]

test/Ocelot.AcceptanceTests/SslTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public void should_not_dangerous_accept_any_server_certificate_validator()
8989
.And(x => _steps.GivenThereIsAConfiguration(configuration))
9090
.And(x => _steps.GivenOcelotIsRunning())
9191
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
92-
.Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.InternalServerError))
92+
.Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.BadGateway))
9393
.BDDfy();
9494
}
9595

test/Ocelot.UnitTests/Responder/ErrorsToHttpStatusCodeMapperTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ public void should_return_service_unavailable(OcelotErrorCode errorCode)
4747

4848
[Theory]
4949
[InlineData(OcelotErrorCode.UnableToCompleteRequestError)]
50-
public void should_return_internal_server_error(OcelotErrorCode errorCode)
50+
public void should_return_bad_gateway_error(OcelotErrorCode errorCode)
5151
{
52-
ShouldMapErrorToStatusCode(errorCode, HttpStatusCode.InternalServerError);
52+
ShouldMapErrorToStatusCode(errorCode, HttpStatusCode.BadGateway);
5353
}
5454

5555
[Theory]

0 commit comments

Comments
 (0)