Created
January 17, 2016 09:06
-
-
Save deangrant/1bcbdf99f8f730fa95b3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Process | |
{ | |
Try | |
{ | |
# Sends HTTPS request to the Slack Web API service. | |
$WebRequest = Invoke-WebRequest -Uri $Uri -Body $PostMessage | |
# Conditional logic to generate custom error message if JSON object response contains a top-level error property. | |
If ($WebRequest.Content -like '*"ok":false*') | |
{ | |
# Terminates with error if the response contains an error property, parses the error code and stops processing of the command. | |
Throw ($WebRequest.Content -split '"error":"')[1] -replace '"}','' | |
} # If | |
} # Try | |
Catch | |
{ | |
# Terminates with error and stops processing of the command. | |
Throw ("Unable to send request to the web service with the following exception: " + $Error[0].Exception.Message ) | |
} # Catch | |
} # Process |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment