Skip to content

Commit

Permalink
Merge pull request #303 from lipkau/fix/#302-HandlingOfErrorResponses
Browse files Browse the repository at this point in the history
Fixed handling of server responses with an error
  • Loading branch information
lipkau authored Jul 17, 2018
2 parents b1f3ca1 + b6ed04b commit 22f7310
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 20 deletions.
5 changes: 4 additions & 1 deletion JiraPS/Private/Resolve-ErrorWebResponse.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ function Resolve-ErrorWebResponse {

foreach ($_error in ($responseObject.errorMessages + $responseObject.errors)) {
# $_error is a PSCustomObject - therefore can't be $false
if (-not $_error.ToString()) { break }
if ($_error -is [PSCustomObject]) {
[String]$_error = ($_error | Out-String)
}
if (-not $_error) { throw "Unable to handle error" }

$writeErrorSplat = @{
Exception = $exception
Expand Down
8 changes: 4 additions & 4 deletions JiraPS/Public/Get-JiraIssueWatcher.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@
Credential = $Credential
}
Write-Debug "[$($MyInvocation.MyCommand.Name)] Invoking JiraMethod with `$parameter"
$result = Invoke-JiraMethod @parameter

Write-Output $result.watchers
# TODO: are these users?
if ($result = Invoke-JiraMethod @parameter) {
Write-Output $result.watchers
# TODO: are these users?
}
}
}

Expand Down
16 changes: 8 additions & 8 deletions JiraPS/Public/Get-JiraVersion.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,14 @@
}

Write-Debug "[$($MyInvocation.MyCommand.Name)] Invoking JiraMethod with `$parameter"
$result = Invoke-JiraMethod @parameter

$result | Where-Object {
$__ = $_.Name
Write-DebugMessage ($__ | Out-String)
$Name | Foreach-Object {
Write-Verbose "[$($MyInvocation.MyCommand.Name)] Matching $_ against $($__)"
$__ -like $_
if ($result = Invoke-JiraMethod @parameter) {
$result | Where-Object {
$__ = $_.Name
Write-DebugMessage ($__ | Out-String)
$Name | Foreach-Object {
Write-Verbose "[$($MyInvocation.MyCommand.Name)] Matching $_ against $($__)"
$__ -like $_
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions JiraPS/Public/Invoke-JiraMethod.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ function Invoke-JiraMethod {
Write-Verbose "[$($MyInvocation.MyCommand.Name)] No Web result object was returned from. This is unusual!"
}
}

end {
Set-TlsLevel -Revert

Expand Down
12 changes: 6 additions & 6 deletions JiraPS/Public/New-JiraIssue.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,12 @@ function New-JiraIssue {
}
Write-Debug "[$($MyInvocation.MyCommand.Name)] Invoking JiraMethod with `$parameter"
if ($PSCmdlet.ShouldProcess($Summary, "Creating new Issue on JIRA")) {
$result = Invoke-JiraMethod @parameter

# REST result will look something like this:
# {"id":"12345","key":"IT-3676","self":"http://jiraserver.example.com/rest/api/latest/issue/12345"}
# This will fetch the created issue to return it with all it'a properties
Write-Output (Get-JiraIssue -Key $result.Key -Credential $Credential)
if ($result = Invoke-JiraMethod @parameter) {
# REST result will look something like this:
# {"id":"12345","key":"IT-3676","self":"http://jiraserver.example.com/rest/api/latest/issue/12345"}
# This will fetch the created issue to return it with all it'a properties
Write-Output (Get-JiraIssue -Key $result.Key -Credential $Credential)
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion JiraPS/Public/Remove-JiraGroupMember.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ function Remove-JiraGroupMember {
}

if ($PassThru) {
Write-Output (Get-JiraGroup -InputObject $g -Credential $Credential)
Write-Output (Get-JiraGroup -InputObject $groupObj -Credential $Credential)
}
}
}
Expand Down

0 comments on commit 22f7310

Please sign in to comment.