Skip to content

Commit

Permalink
refactor(StashClient,WerckerClient): separate catch blocks for Spinna…
Browse files Browse the repository at this point in the history
…kerNetworkException for readability
  • Loading branch information
SheetalAtre committed Sep 11, 2023
1 parent 323f19f commit 3cee198
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,21 @@ class CommitController extends AbstractCommitController {
CompareCommitsResponse commitsResponse
try {
commitsResponse = stashMaster.stashClient.getCompareCommits(projectKey, repositorySlug, requestParams)
} catch (SpinnakerServerException e) {
if (e instanceof SpinnakerNetworkException) {
throw new NotFoundException("Could not find the server ${stashMaster.baseUrl}")
} else if (e instanceof SpinnakerHttpException && ((SpinnakerHttpException)e).getResponseCode() == 404) {
} catch (SpinnakerNetworkException e) {
throw new NotFoundException("Could not find the server ${stashMaster.baseUrl}")
} catch (SpinnakerHttpException e) {
if(e.getResponseCode() == 404) {
return getNotFoundCommitsResponse(projectKey, repositorySlug, requestParams.to, requestParams.from, stashMaster.baseUrl)
}
log.error(
}
log.error(
"Failed to fetch commits for {}/{}, reason: {}",
projectKey, repositorySlug, e.message
)
}catch (SpinnakerServerException e) {
log.error(
"Failed to fetch commits for {}/{}, reason: {}",
projectKey, repositorySlug, e.message
)
}

List result = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ class StashMaster extends AbstractScmMaster {
List<String> listDirectory(String projectKey, String repositorySlug, String path, String ref) {
try {
return stashClient.listDirectory(projectKey, repositorySlug, path, ref).toChildFilenames()
} catch (SpinnakerServerException e) {
if (e instanceof SpinnakerNetworkException) {
throw new NotFoundException("Could not find the server ${baseUrl}")
}
}catch (SpinnakerNetworkException e) {
throw new NotFoundException("Could not find the server ${baseUrl}")
}
catch (SpinnakerServerException e) {
log.error(
"Failed to fetch file from {}/{}/{}, reason: {}",
projectKey, repositorySlug, path, e.message
Expand All @@ -61,10 +61,9 @@ class StashMaster extends AbstractScmMaster {
contents += response.toTextContents() + "\n"
}
return contents
} catch (SpinnakerServerException e) {
if (e instanceof SpinnakerNetworkException) {
throw new NotFoundException("Could not find the server ${baseUrl}")
}
} catch (SpinnakerNetworkException e) {
throw new NotFoundException("Could not find the server ${baseUrl}")
} catch(SpinnakerServerException e) {
log.error(
"Failed to fetch file from {}/{}/{}, reason: {}",
projectKey, repositorySlug, path, e.message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ class WerckerBuildMonitor extends CommonPollingMonitor<PipelineDelta, PipelinePo
))
} catch (e) {
log.error("Error processing runs for [{}:{}]", kv("master", master), kv("pipeline", pipeline), e)
if (e.getCause() instanceof SpinnakerServerException) {
if (e instanceof SpinnakerServerException) {
def re = (SpinnakerServerException) e.getCause()
def url = null
if (re instanceof SpinnakerHttpException){
Expand Down

0 comments on commit 3cee198

Please sign in to comment.