Merged in develop

This commit is contained in:
Marc Denman
2017-03-14 21:50:03 +00:00
4 changed files with 18 additions and 25 deletions

View File

@ -1,17 +1,16 @@
using System.Collections.Generic;
using System.Linq;
using Ocelot.Errors;
using Ocelot.Responses;
namespace Ocelot.Responder
{
public class ErrorsToHttpStatusCodeMapper : IErrorsToHttpStatusCodeMapper
{
public Response<int> Map(List<Error> errors)
public int Map(List<Error> errors)
{
if (errors.Any(e => e.Code == OcelotErrorCode.UnauthenticatedError))
{
return new OkResponse<int>(401);
return 401;
}
if (errors.Any(e => e.Code == OcelotErrorCode.UnauthorizedError
@ -19,20 +18,20 @@ namespace Ocelot.Responder
|| e.Code == OcelotErrorCode.UserDoesNotHaveClaimError
|| e.Code == OcelotErrorCode.CannotFindClaimError))
{
return new OkResponse<int>(403);
return 403;
}
if (errors.Any(e => e.Code == OcelotErrorCode.RequestTimedOutError))
{
return new OkResponse<int>(503);
}
return 503;
}
if (errors.Any(e => e.Code == OcelotErrorCode.UnableToFindDownstreamRouteError))
{
return new OkResponse<int>(404);
return 404;
}
return new OkResponse<int>(404);
return 404;
}
}
}

View File

@ -1,11 +1,13 @@
using System.Collections.Generic;
using Ocelot.Errors;
using Ocelot.Responses;
namespace Ocelot.Responder
{
{
/// <summary>
/// Map a list OceoltErrors to a single appropriate HTTP status code
/// </summary>
public interface IErrorsToHttpStatusCodeMapper
{
Response<int> Map(List<Error> errors);
int Map(List<Error> errors);
}
}

View File

@ -56,18 +56,11 @@ namespace Ocelot.Responder.Middleware
_logger.LogTrace($"completed {MiddlwareName}");
}
private void SetErrorResponse(HttpContext context, List<Error> errors)
{
private void SetErrorResponse(HttpContext context, List<Error> errors)
{
var statusCode = _codeMapper.Map(errors);
if (!statusCode.IsError)
{
_responder.SetErrorResponseOnContext(context, statusCode.Data);
}
else
{
_responder.SetErrorResponseOnContext(context, 500);
}
_responder.SetErrorResponseOnContext(context, statusCode);
}
}
}