Wrapped json parsing with try/catch

This commit is contained in:
Petri Asikainen 2021-05-25 23:24:36 +03:00
parent 5a10799eb8
commit 4810bbf54f

View file

@ -85,6 +85,7 @@
Write-Verbose $webResponse.Content
# API returned a Content: lets work wit it
try{
$response = ConvertFrom-Json -InputObject $webResponse.Content
if ($response.status -eq "error") {
@ -106,6 +107,11 @@
$result
}
}
catch {
Write-Warning "Cannot parse server response. To debug try to add -Verbose with command."
}
}
elseif ($webResponse.StatusCode -eq "Unauthorized") {
Write-Error "[$($MyInvocation.MyCommand.Name)] You are not Authorized to access the resource, check your token is correct"
}