Skip to content

Commit

Permalink
Fix exception being logged
Browse files Browse the repository at this point in the history
Update `LambdaServerWasShutDown()` to avoid exception being logged when background task throws an exception.
  • Loading branch information
martincostello committed Nov 25, 2024
1 parent b71e148 commit 95f4bea
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions samples/MinimalApi.Tests/ApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,23 @@ private static CancellationTokenSource GetCancellationTokenSourceForResponseAvai
private static bool LambdaServerWasShutDown(Exception exception)
{
if (exception is not TargetInvocationException targetException ||
targetException.InnerException is not HttpRequestException httpException ||
httpException.InnerException is not SocketException socketException)
targetException.InnerException is not HttpRequestException httpException)
{
return false;
}

return socketException.SocketErrorCode == SocketError.ConnectionRefused;
var inner = httpException.InnerException;

while (inner is not null)
{
if (inner is SocketException socketException)
{
return socketException.SocketErrorCode is SocketError.ConnectionRefused or SocketError.ConnectionReset;
}

inner = inner.InnerException;
}

return false;
}
}

0 comments on commit 95f4bea

Please sign in to comment.