#271 Added some extra logging (#276)

This commit is contained in:
Tom Pallister 2018-03-14 18:49:41 +00:00 committed by GitHub
parent fd2c5364fc
commit d24df36420
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 58 additions and 4 deletions

View File

@ -39,8 +39,7 @@ namespace Ocelot.Requester
} }
catch (TimeoutRejectedException exception) catch (TimeoutRejectedException exception)
{ {
return return new ErrorResponse<HttpResponseMessage>(new RequestTimedOutError(exception));
new ErrorResponse<HttpResponseMessage>(new RequestTimedOutError(exception));
} }
catch (BrokenCircuitException exception) catch (BrokenCircuitException exception)
{ {

View File

@ -6,7 +6,7 @@ namespace Ocelot.Requester
public class RequestTimedOutError : Error public class RequestTimedOutError : Error
{ {
public RequestTimedOutError(Exception exception) public RequestTimedOutError(Exception exception)
: base($"Timeout making http request, exception: {exception.Message}", OcelotErrorCode.RequestTimedOutError) : base($"Timeout making http request, exception: {exception}", OcelotErrorCode.RequestTimedOutError)
{ {
} }
} }

View File

@ -6,7 +6,7 @@ namespace Ocelot.Requester
public class UnableToCompleteRequestError : Error public class UnableToCompleteRequestError : Error
{ {
public UnableToCompleteRequestError(Exception exception) public UnableToCompleteRequestError(Exception exception)
: base($"Error making http request, exception: {exception.Message}", OcelotErrorCode.UnableToCompleteRequestError) : base($"Error making http request, exception: {exception}", OcelotErrorCode.UnableToCompleteRequestError)
{ {
} }
} }

View File

@ -39,6 +39,12 @@ namespace Ocelot.Responder.Middleware
{ {
var errors = context.Errors; var errors = context.Errors;
_logger.LogError($"{errors.Count} pipeline errors found in {MiddlewareName}. Setting error response status code"); _logger.LogError($"{errors.Count} pipeline errors found in {MiddlewareName}. Setting error response status code");
foreach(var error in errors)
{
_logger.LogError(error.Message);
}
SetErrorResponse(context.HttpContext, errors); SetErrorResponse(context.HttpContext, errors);
} }
else else

View File

@ -922,6 +922,55 @@ namespace Ocelot.AcceptanceTests
.BDDfy(); .BDDfy();
} }
[Fact]
public void should_fix_issue_271()
{
var configuration = new FileConfiguration
{
ReRoutes = new List<FileReRoute>
{
new FileReRoute
{
DownstreamPathTemplate = "/api/v1/{everything}",
DownstreamScheme = "http",
UpstreamPathTemplate = "/api/v1/{everything}",
UpstreamHttpMethod = new List<string> { "Get", "Put", "Post" },
DownstreamHostAndPorts = new List<FileHostAndPort>
{
new FileHostAndPort
{
Host = "localhost",
Port = 54879,
}
},
},
new FileReRoute
{
DownstreamPathTemplate = "/connect/token",
DownstreamScheme = "http",
UpstreamPathTemplate = "/connect/token",
UpstreamHttpMethod = new List<string> { "Post" },
DownstreamHostAndPorts = new List<FileHostAndPort>
{
new FileHostAndPort
{
Host = "localhost",
Port = 5001,
}
},
}
}
};
this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:54879/", "/api/v1/modules/Test", 200, "Hello from Laura"))
.And(x => _steps.GivenThereIsAConfiguration(configuration))
.And(x => _steps.GivenOcelotIsRunning())
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/api/v1/modules/Test"))
.Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
.And(x => _steps.ThenTheResponseBodyShouldBe("Hello from Laura"))
.BDDfy();
}
private void GivenThereIsAServiceRunningOn(string baseUrl, string basePath, int statusCode, string responseBody) private void GivenThereIsAServiceRunningOn(string baseUrl, string basePath, int statusCode, string responseBody)
{ {
_builder = new WebHostBuilder() _builder = new WebHostBuilder()