Skip to content

Commit

Permalink
[#6577] Can you add a log line for this exception? (#6587)
Browse files Browse the repository at this point in the history
* Added log in ProcessAsync method. Updated CloudAdapter unit tests.

* Unit test updated

* Changed LogWarning to LogError

* Suggested changes applied

---------

Co-authored-by: Emiliano Quiroga <emiliano.quiroga@7-11.com>
  • Loading branch information
2 people authored and Tracy Boehrer committed Feb 13, 2023
1 parent 27ea26e commit daac32c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,12 @@ public async Task ProcessAsync(HttpRequest httpRequest, HttpResponse httpRespons
httpResponse.StatusCode = (int)HttpStatusCode.MethodNotAllowed;
}
}
catch (UnauthorizedAccessException)
catch (UnauthorizedAccessException ex)
{
// handle unauthorized here as this layer creates the http response
httpResponse.StatusCode = (int)HttpStatusCode.Unauthorized;

Logger.LogError(ex.ToString());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -825,14 +825,25 @@ public async Task ExpiredTokenShouldThrowUnauthorizedAccessException()
var httpResponseMock = new Mock<HttpResponse>().SetupAllProperties();
httpResponseMock.Setup(r => r.Body).Returns(response);

var loggerMock = new Mock<ILogger<CloudAdapter>>();

var bot = new InvokeResponseBot();

// Act
var adapter = new CloudAdapter();
var adapter = new CloudAdapter(BotFrameworkAuthenticationFactory.Create(), loggerMock.Object);
await adapter.ProcessAsync(httpRequestMock.Object, httpResponseMock.Object, bot);

// Assert
Assert.Equal((int)HttpStatusCode.Unauthorized, httpResponseMock.Object.StatusCode);

loggerMock.Verify(
x => x.Log(
LogLevel.Error,
It.IsAny<EventId>(),
It.Is<It.IsAnyType>((o, t) => o.ToString().Contains("The token has expired")),
It.IsAny<Exception>(),
(Func<It.IsAnyType, Exception, string>)It.IsAny<object>()),
Times.Once);
}

private static Stream CreateMessageActivityStream(string userId, string channelId, string conversationId, string recipient, string relatesToActivityId)
Expand Down

0 comments on commit daac32c

Please sign in to comment.