#603 return 502 on HttpRequestException

This commit is contained in:
jlukawska
2020-01-22 14:55:41 +01:00
parent f35a07a3da
commit 68e3ae8cdd
6 changed files with 37 additions and 4 deletions

View File

@ -39,6 +39,7 @@
CannotAddPlaceholderError = 34,
CannotRemovePlaceholderError = 35,
QuotaExceededError = 36,
RequestCanceled = 37,
RequestCanceled = 37,
ConnectionToDownstreamServiceError = 38,
}
}

View File

@ -0,0 +1,13 @@
using Ocelot.Errors;
using System;
namespace Ocelot.Requester
{
class ConnectionToDownstreamServiceError : Error
{
public ConnectionToDownstreamServiceError(Exception exception)
: base($"Error connecting to downstream service, exception: {exception}", OcelotErrorCode.ConnectionToDownstreamServiceError)
{
}
}
}

View File

@ -4,6 +4,8 @@ namespace Ocelot.Requester
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Net.Sockets;
public class HttpExeptionToErrorMapper : IExceptionToErrorMapper
{
@ -28,6 +30,11 @@ namespace Ocelot.Requester
return new RequestCanceledError(exception.Message);
}
if (type == typeof(HttpRequestException))
{
return new ConnectionToDownstreamServiceError(exception);
}
return new UnableToCompleteRequestError(exception);
}
}

View File

@ -38,11 +38,16 @@ namespace Ocelot.Responder
if (errors.Any(e => e.Code == OcelotErrorCode.UnableToFindDownstreamRouteError))
{
return 404;
}
if (errors.Any(e => e.Code == OcelotErrorCode.ConnectionToDownstreamServiceError))
{
return 502;
}
if (errors.Any(e => e.Code == OcelotErrorCode.UnableToCompleteRequestError))
{
return 502;
return 500;
}
return 404;