Merge pull request #125 from PetriAsi/fix/invoke-snipeitmethod-error-handling-#91

Wrapped json parsing with try/catch
This commit is contained in:
Petri Asikainen 2021-05-26 13:39:08 +03:00 committed by GitHub
commit eed5a09ba2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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"
}