Skip to content

Commit

Permalink
#21 added checking for errors within $Execute content
Browse files Browse the repository at this point in the history
  • Loading branch information
PrzemyslawKlys committed Jul 29, 2020
1 parent cd87222 commit ab5acae
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions Public/Send-TeamsMessage.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function Send-TeamsMessage {
[string]$Color,
[switch]$HideOriginalBody,
[System.Collections.IDictionary[]]$Sections,
[bool] $Supress = $true,
[alias('Supress')][bool] $Suppress = $true,
[switch] $ShowErrors
)
if ($SectionsInput) {
Expand All @@ -37,7 +37,7 @@ function Send-TeamsMessage {
-MessageSummary $MessageSummary `
-HideOriginalBody:$HideOriginalBody.IsPresent
try {
$Execute = Invoke-RestMethod -Uri $Uri -Method Post -Body $Body -ContentType 'application/json; charset=UTF-8'
$Execute = Invoke-RestMethod -Uri $Uri -Method Post -Body $Body -ContentType 'application/json; charset=UTF-8' -ErrorAction Stop
} catch {
$ErrorMessage = $_.Exception.Message -replace "`n", " " -replace "`r", " "
if ($ShowErrors) {
Expand All @@ -46,8 +46,11 @@ function Send-TeamsMessage {
Write-Warning "Send-TeamsMessage - Couldn't send message. Error: $ErrorMessage"
}
}
if ($Execute -like '*failed*' -or $Execute -like '*error*') {
Write-Warning "Send-TeamsMessage - Couldn't send message. Execute message: $Execute"
}
Write-Verbose "Send-TeamsMessage - Execute $Execute Body $Body"
if (-not $Supress) { return $Body }
if (-not $Suppress) { return $Body }
}

Register-ArgumentCompleter -CommandName Send-TeamsMessage -ParameterName Color -ScriptBlock { $Script:RGBColors.Keys }

0 comments on commit ab5acae

Please sign in to comment.