• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ThreeMammals / Ocelot / 24430351266

15 Apr 2026 12:43AM UTC coverage: 92.604% (+0.08%) from 92.525%
24430351266

Pull #2379

github

web-flow
Merge 6c93d12eb into 5eeb9ccca
Pull Request #2379: #2375 #2376 Map non-ASCII header `HttpRequestException` to 400 Bad Request

6398 of 6909 relevant lines covered (92.6%)

2688.99 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.89
src/Ocelot/Responder/ErrorsToHttpStatusCodeMapper.cs
1
using Microsoft.AspNetCore.Http;
2
using Ocelot.Errors;
3

4
namespace Ocelot.Responder;
5

6
public class ErrorsToHttpStatusCodeMapper : IErrorsToHttpStatusCodeMapper
7
{
8
    public int Map(List<Error> errors)
9
    {
10
        if (errors.Any(e => e.Code == OcelotErrorCode.UnauthenticatedError))
79✔
11
        {
12
            return 401;
2✔
13
        }
14

15
        if (errors.Any(e => e.Code == OcelotErrorCode.UnauthorizedError
72✔
16
            || e.Code == OcelotErrorCode.ClaimValueNotAuthorizedError
72✔
17
            || e.Code == OcelotErrorCode.ScopeNotAuthorizedError
72✔
18
            || e.Code == OcelotErrorCode.UserDoesNotHaveClaimError
72✔
19
            || e.Code == OcelotErrorCode.CannotFindClaimError))
72✔
20
        {
21
            return 403;
6✔
22
        }
23

24
        if (errors.Any(e => e.Code == OcelotErrorCode.QuotaExceededError))
59✔
25
        {
26
            return errors.Single(e => e.Code == OcelotErrorCode.QuotaExceededError).HttpStatusCode;
×
27
        }
28

29
        if (errors.Any(e => e.Code == OcelotErrorCode.RequestTimedOutError))
59✔
30
        {
31
            return StatusCodes.Status503ServiceUnavailable;
2✔
32
        }
33

34
        if (errors.Any(e => e.Code == OcelotErrorCode.RequestCanceled))
54✔
35
        {
36
            // status code refer to
37
            // https://stackoverflow.com/questions/46234679/what-is-the-correct-http-status-code-for-a-cancelled-request?answertab=votes#tab-top
38
            // https://httpstatuses.com/499
39
            return StatusCodes.Status499ClientClosedRequest;
×
40
        }
41

42
        if (errors.Any(e => e.Code == OcelotErrorCode.UnableToFindDownstreamRouteError))
54✔
43
        {
44
            return 404;
1✔
45
        }
46

47
        if (errors.Any(e => e.Code == OcelotErrorCode.ConnectionToDownstreamServiceError))
52✔
48
        {
49
            return 502;
1✔
50
        }
51

52
        if (errors.Any(e => e.Code == OcelotErrorCode.UnableToCompleteRequestError
50✔
53
            || e.Code == OcelotErrorCode.CouldNotFindLoadBalancerCreator
50✔
54
            || e.Code == OcelotErrorCode.ErrorInvokingLoadBalancerCreator))
50✔
55
        {
56
            return 500;
3✔
57
        }
58

59
        if (errors.Any(e => e.Code == OcelotErrorCode.PayloadTooLargeError))
44✔
60
        {
61
            return 413;
×
62
        }
63

64
        if (errors.Any(e => e.Code == OcelotErrorCode.BadRequestError))
44✔
65
        {
66
            return StatusCodes.Status400BadRequest;
1✔
67
        }
68

69
        return 404;
21✔
70
    }
71
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc