mirror of
https://github.com/snazy2000/SnipeitPS.git
synced 2025-12-13 18:02:30 +00:00
Wrapped json parsing with try/catch
This commit is contained in:
parent
5a10799eb8
commit
4810bbf54f
1 changed files with 22 additions and 16 deletions
|
|
@ -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"
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue