|
85 | 85 | Write-Verbose $webResponse.Content |
86 | 86 |
|
87 | 87 | # API returned a Content: lets work wit it |
88 | | - $response = ConvertFrom-Json -InputObject $webResponse.Content |
89 | | - |
90 | | - if ($response.status -eq "error") { |
91 | | - Write-Verbose "[$($MyInvocation.MyCommand.Name)] An error response was received from; resolving" |
92 | | - # This could be handled nicely in an function such as: |
93 | | - # ResolveError $response -WriteError |
94 | | - Write-Error $($response.messages | Out-String) |
95 | | - } |
96 | | - else { |
97 | | - $result = $response |
98 | | - if (($response) -and ($response | Get-Member -Name payload)) |
99 | | - { |
100 | | - $result = $response.payload |
| 88 | + try{ |
| 89 | + $response = ConvertFrom-Json -InputObject $webResponse.Content |
| 90 | + |
| 91 | + if ($response.status -eq "error") { |
| 92 | + Write-Verbose "[$($MyInvocation.MyCommand.Name)] An error response was received from; resolving" |
| 93 | + # This could be handled nicely in an function such as: |
| 94 | + # ResolveError $response -WriteError |
| 95 | + Write-Error $($response.messages | Out-String) |
101 | 96 | } |
102 | | - elseif (($response) -and ($response | Get-Member -Name rows)) { |
103 | | - $result = $response.rows |
| 97 | + else { |
| 98 | + $result = $response |
| 99 | + if (($response) -and ($response | Get-Member -Name payload)) |
| 100 | + { |
| 101 | + $result = $response.payload |
| 102 | + } |
| 103 | + elseif (($response) -and ($response | Get-Member -Name rows)) { |
| 104 | + $result = $response.rows |
| 105 | + } |
| 106 | + |
| 107 | + $result |
104 | 108 | } |
105 | | - |
106 | | - $result |
107 | 109 | } |
| 110 | + catch { |
| 111 | + Write-Warning "Cannot parse server response. To debug try to add -Verbose with command." |
| 112 | + } |
| 113 | + |
108 | 114 | } |
109 | 115 | elseif ($webResponse.StatusCode -eq "Unauthorized") { |
110 | 116 | Write-Error "[$($MyInvocation.MyCommand.Name)] You are not Authorized to access the resource, check your token is correct" |
|
0 commit comments