mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-19 21:48:15 +08:00
#603 return 502 on HttpRequestException
This commit is contained in:
@ -39,6 +39,7 @@
|
||||
CannotAddPlaceholderError = 34,
|
||||
CannotRemovePlaceholderError = 35,
|
||||
QuotaExceededError = 36,
|
||||
RequestCanceled = 37,
|
||||
RequestCanceled = 37,
|
||||
ConnectionToDownstreamServiceError = 38,
|
||||
}
|
||||
}
|
||||
|
13
src/Ocelot/Requester/ConnectionToDownstreamServiceError.cs
Normal file
13
src/Ocelot/Requester/ConnectionToDownstreamServiceError.cs
Normal 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)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
Reference in New Issue
Block a user