Skip to content

Commit cdbd8e8

Browse files
committed
http error code tests and docs
1 parent 3dfcff8 commit cdbd8e8

File tree

6 files changed

+29
-6
lines changed

6 files changed

+29
-6
lines changed

docs/features/errorcodes.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Http Error Status Codes
2+
=======================
3+
4+
Ocelot will return HTTP status error codes based on internal logic in certain siturations:
5+
- 401 if the authentication middleware runs and the user is not authenticated.
6+
- 403 if the authorisation middleware runs and the user is unauthenticated, claim value not authroised, scope not authorised, user doesnt have required claim or cannot find claim.
7+
- 503 if the downstream request times out.
8+
- 499 if the request is cancelled by the client.
9+
- 404 if unable to find a downstream route.
10+
- 502 if unable to connect to downstream service.
11+
- 500 if unable to complete the HTTP request downstream and the exception is not OperationCanceledException or HttpRequestException.
12+
- 404 if Ocelot is unable to map an internal error code to a HTTP status code.
13+

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Thanks for taking a look at the Ocelot documentation. Please use the left hand n
4242
features/loadbalancer
4343
features/delegatinghandlers
4444
features/raft
45+
features/errorcodes
4546

4647
.. toctree::
4748
:maxdepth: 2

src/Ocelot/Requester/ConnectionToDownstreamServiceError.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace Ocelot.Requester
55
{
6-
class ConnectionToDownstreamServiceError : Error
6+
public class ConnectionToDownstreamServiceError : Error
77
{
88
public ConnectionToDownstreamServiceError(Exception exception)
99
: base($"Error connecting to downstream service, exception: {exception}", OcelotErrorCode.ConnectionToDownstreamServiceError)

src/Ocelot/Requester/HttpExeptionToErrorMapper.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ namespace Ocelot.Requester
55
using System;
66
using System.Collections.Generic;
77
using System.Net.Http;
8-
using System.Net.Sockets;
98

109
public class HttpExeptionToErrorMapper : IExceptionToErrorMapper
1110
{

src/Ocelot/Responder/IErrorsToHttpStatusCodeMapper.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
using Ocelot.Errors;
2-
using System.Collections.Generic;
1+
namespace Ocelot.Responder
2+
{
3+
using System.Net;
4+
using Ocelot.Errors;
5+
using System.Collections.Generic;
36

4-
namespace Ocelot.Responder
5-
{
67
/// <summary>
78
/// Map a list OceoltErrors to a single appropriate HTTP status code
89
/// </summary>

test/Ocelot.UnitTests/Requester/HttpExeptionToErrorMapperTests.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Shouldly;
88
using System;
99
using System.Collections.Generic;
10+
using System.Net.Http;
1011
using System.Threading.Tasks;
1112
using Xunit;
1213

@@ -38,6 +39,14 @@ public void should_return_request_canceled()
3839
error.ShouldBeOfType<RequestCanceledError>();
3940
}
4041

42+
[Fact]
43+
public void should_return_ConnectionToDownstreamServiceError()
44+
{
45+
var error = _mapper.Map(new HttpRequestException());
46+
47+
error.ShouldBeOfType<ConnectionToDownstreamServiceError>();
48+
}
49+
4150
[Fact]
4251
public void should_return_request_canceled_for_subtype()
4352
{

0 commit comments

Comments
 (0)