TheJumpCloud / jcapi-powershell

MIT License
10 stars 3 forks source link

CUT-3858: Retry API Call Function #70

Closed gweinjc closed 8 months ago

gweinjc commented 8 months ago

Issues

What does this solve?

This fix attempts to alleviate the issue of unexpected 503 errors when making SDK calls in larger scripts which results in errors or incomplete datasets being returned. We have added a do-while loop with a counter to the API call function that will detect if a 503 error is present, wait a period of time and then re-attempt the call until either the call is successful or the max counter is reached.

Is there anything particularly tricky?

503 errors are inherently unreliable and difficult to test for. We can manually test this by replacing the lookup for a 503 error with a more replicable error, such as 400 (Bad Request).

How should this be tested?

  1. Find a SDK function that is suitable for testing, ex: Get-JCSdkUserAssociation
  2. Within the process block, look for the line that contains If ($JCHttpResponse.Result.StatusCode -eq 503) and replace the 503 with 400.
  3. Import the local SDK .psd1
    • Import-Module '/Users/USER/Documents/GitHub/jcapi-powershell/SDKs/PowerShell/JumpCloud.SDK.V2/JumpCloud.SDK.V2.psd1' -force
  4. Provide the function an incomplete entry to force a 400 error
    • ex: Get-JCSdkUserAssociation -UserID '6120152163f8976f332dafc' -target active_directory
    • The UserID is not the correct length, therefore will always fail