Modules/businessdev.ALbuild.Core/Private/Test-ALbuildTransientHttpFailure.ps1

function Test-ALbuildTransientHttpFailure {
    <#
    .SYNOPSIS
        Tells whether a failed licensing request is worth attempting again.
 
    .DESCRIPTION
        A separate function because it is the one decision in the retry loop that carries judgement,
        and it can be tested without fabricating an HTTP exception - which cannot be built the same
        way on PowerShell 7 and Windows PowerShell 5.1.
 
        Retried:
          0 no answer at all - timeout, dropped connection, DNS or TLS failure.
          400 the licensing service's answer to two verifications of one tenant arriving together.
                Verifying moves the license's validity forward, so simultaneous verifications are
                simultaneous writes and one gets rejected. Measured: two concurrent calls both
                succeed, four produce two rejections.
          408, 425, 429, 5xx the usual momentary conditions.
 
        Everything else is an answer about the license itself (401, 403, 404 ...) and repeating the
        request only delays telling the user.
 
    .PARAMETER StatusCode
        HTTP status code, or 0 when the service was not reached.
 
    .OUTPUTS
        Boolean.
    #>

    [CmdletBinding()]
    [OutputType([bool])]
    param([Parameter(Mandatory)] [int] $StatusCode)

    if ($StatusCode -eq 0) { return $true }
    if ($StatusCode -in @(400, 408, 425, 429)) { return $true }
    return ($StatusCode -ge 500)
}