Skip to content

Commit

Permalink
Add exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
oysand committed Nov 25, 2024
1 parent 44171c8 commit 0cd2359
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions backend/api/EventHandlers/TeamsMessageEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,16 @@ private async void OnTeamsMessageReceived(object? sender, TeamsMessageEventArgs
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

var content = CreateTeamsMessageCard(e.TeamsMessage);

var response = await client.PostAsync(url, content);
HttpResponseMessage? response;
try
{
response = await client.PostAsync(url, content);
}
catch (Exception ex)
{
_logger.LogError(ex, "Failed to send message to Teams");
return;
}
if (response.IsSuccessStatusCode)
{
_logger.LogInformation("Post request via teams incomming webhook was successful, Status Code: {response.StatusCode}", response.StatusCode);
Expand All @@ -74,4 +82,3 @@ private static StringContent CreateTeamsMessageCard(string message)
}
}
}

0 comments on commit 0cd2359

Please sign in to comment.