Skip to content

Commit 1b05b65

Browse files
committed
Added handling of 429 errors
1 parent 3b36153 commit 1b05b65

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

Slack.Backup/Private/api/Invoke-SlackAPI.ps1

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,17 @@ function Invoke-SlackAPI {
3131
$uri = $uriRequest.ToString()
3232
}
3333

34-
$response = Invoke-WebRequest -Method Get -Uri $uri -Headers $headers
34+
try {
35+
$response = Invoke-WebRequest -Method Get -Uri $uri -Headers $headers
36+
}
37+
catch [Microsoft.PowerShell.Commands.HttpResponseException] {
38+
if ($_.Exception.Response.StatusCode -eq 429) {
39+
[int] $delay = [int](($_.Exception.Response.Headers | Where-Object Key -eq 'Retry-After').Value[0])
40+
Write-Host -Message "Retry caught, delaying $delay s"
41+
Start-Sleep -Seconds $delay
42+
return Invoke-SlackAPI $Method $Token $Parameters
43+
}
44+
}
3545
$response = $response.Content | ConvertFrom-Json
3646
if ($response.ok) {
3747
$response

Slack.Backup/Slack.Backup.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
@{
33
RootModule = 'Slack.Backup.psm1'
4-
ModuleVersion = '1.1.1'
4+
ModuleVersion = '1.1.3'
55
GUID = '5fca212b-de20-40cb-ba38-e6114263bfaa'
66
Author = 'Alan Plocieniak'
77
CompanyName = 'Alan Plocieniak'

0 commit comments

Comments
 (0)