I'm using SAP's Raylight RESTful SDK to get a list of universes from the BusinessObject Enterprise repository.
To get all of the universes, the request needs to be called repeatedly, incrementing the offset parameter until the request returns a Not Found [404] error.
Current approach:
$baseUrl = 'http://<server>:6405/biprws/raylight/v1'
$headers = @{}
$headers.Add("Accept", "application/json")
$headers.Add("Content-Type", "application/json")
$headers.Add("x-sap-logontoken", $Token)
$offset = 0
$limit = 50
try {
do {
$Path = "/universes?offset=$offset&limit=$limit"
$response = Invoke-WebRequest "$baseUrl$Path" -Headers $headers
($response | ConvertFrom-Json).universes.universe
$offset += $limit
} until ( $response.StatusCode -eq [System.Net.HttpStatusCode]::NotFound )
}
catch {
# catches 404 too
Write-Debug "StatusCode: $($_.Exception.Response.StatusCode.Value__)"
}
While the code returns the expected results, I not sure that I like how the code will always exit via the catch. I could remove the try/catch, but that will leave the code exposed to other errors.
Is there a way to improve this?