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

ThreeMammals / Ocelot / 26761608736

01 Jun 2026 02:34PM UTC coverage: 0.0% (-95.4%) from 95.403%
26761608736

Pull #2394

github

web-flow
Merge e39fc0db2 into e4022a7d8
Pull Request #2394: Harden `FileConfigurationPoller` against timer reentrancy and callback thread leaks, and stabilize `TimeoutDelegatingHandler` timeout test

0 of 7112 relevant lines covered (0.0%)

0.0 hits per line

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

0.0
src/Ocelot/Requester/HttpExceptionToErrorMapper.cs
1
using Microsoft.AspNetCore.Http;
2
using Microsoft.Extensions.DependencyInjection;
3
using Ocelot.Errors;
4
using Ocelot.Request.Mapper;
5

6
namespace Ocelot.Requester;
7

8
public class HttpExceptionToErrorMapper : IExceptionToErrorMapper
9
{
10
    /// <summary>This is a dictionary of custom mappers for exceptions.</summary>
11
    private readonly IDictionary<Type, Func<Exception, Error>> _mappers;
12

13
    public HttpExceptionToErrorMapper(IServiceProvider serviceProvider)
×
14
    {
×
15
        _mappers = serviceProvider.GetService<IDictionary<Type, Func<Exception, Error>>>();
×
16
    }
×
17

18
    public Error Map(Exception exception)
19
    {
×
20
        var type = exception.GetType();
×
21

22
        // If there is a custom mapper for this exception type, use it
23
        // The idea is the following: When implementing features or providers,
24
        // you can provide a custom mapper
25
        if (_mappers != null && _mappers.TryGetValue(type, out var mapper))
×
26
        {
×
27
            return mapper(exception);
×
28
        }
29

30
        // here are mapped the exceptions thrown from Ocelot core application
31
        if (type == typeof(TimeoutException))
×
32
        {
×
33
            return new RequestTimedOutError(exception); // -> 503 Service Unavailable; TODO but it should actually be 504 Gateway Timeout
×
34
        }
35

36
        if (type == typeof(OperationCanceledException) || type.IsSubclassOf(typeof(OperationCanceledException)))
×
37
        {
×
38
            return new RequestCanceledError(exception.Message);
×
39
        }
40

41
        // Bug #2376 -> https://github.com/ThreeMammals/Ocelot/issues/2376
42
        // Late Catch: Map the HttpRequestException to a 400 Bad Request.
43
        // If the header format is invalid, HttpClient throws this exception locally.
44
        // By catching it here, we ensure Ocelot returns a clean 4xx client error instead of a generic 502 Bad Gateway.
45
        if (exception is HttpRequestException && exception.Message.Contains("Request headers must contain only ASCII characters."))
×
46
        {
×
47
            return new BadRequestError(exception); // -> 400 Bad Request
×
48
        }
49

50
        // Map to a 413 Content Too Large (prior Request Entity Too Large) or 502 Bad Gateway
51
        if (type == typeof(HttpRequestException) || type == typeof(TimeoutException))
×
52
        {
×
53
            // Inner exception is a BadHttpRequestException, and only this exception exposes the StatusCode property.
54
            // We check if the inner exception is a BadHttpRequestException and if the StatusCode is 413, we return a PayloadTooLargeError
55
            if (exception.InnerException is BadHttpRequestException { StatusCode: StatusCodes.Status413RequestEntityTooLarge })
×
56
            {
×
57
                return new PayloadTooLargeError(exception); // -> 413 Content Too Large
×
58
            }
59

60
            return new ConnectionToDownstreamServiceError(exception); // -> 502 Bad Gateway
×
61
        }
62

63
        return new UnableToCompleteRequestError(exception); // -> 500 Internal Server Error
×
64
    }
×
65
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc