Skip to content

Commit

Permalink
Fix nullpointer that happens in exception handler on HttpClientRespon…
Browse files Browse the repository at this point in the history
…seException. (#37)
  • Loading branch information
matrei authored Dec 5, 2022
1 parent 8d0ac7d commit a4c022a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
11 changes: 4 additions & 7 deletions grails-app/services/com/bintray/BintrayService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,15 @@ class BintrayService implements GrailsConfigurationAware {
@Deprecated
BintrayPackage fetchBintrayPackage(String name, String organization = this.organization, String repository = this.repository) throws IOException {
final String url = "/packages/${organization}/${repository}/${name}".toString()
HttpResponse<BintrayPackage> response = null
try {
log.trace("sending request to {}", url)
response = client
HttpResponse<BintrayPackage> response = client
.exchange(HttpRequest.GET(url).basicAuth(username, token), BintrayPackage)
log.trace("fetched bintray packages {}", url)
return response?.body()

} catch(HttpClientResponseException e) {
log.warn 'Response {}. Could not fetch bintray package at {}', response?.status?.code, name
log.warn 'Response {}. Could not fetch bintray package at {}', e.status.code, name
}
null
}
Expand All @@ -72,9 +71,8 @@ class BintrayService implements GrailsConfigurationAware {
String url = UriBuilder.of("/repos/grails/plugins/packages").queryParam("start_pos", startPos).build()
log.debug("fetching {}", url)

HttpResponse<List<BintrayPackageSimple>> response = null
try {
response = client.exchange(HttpRequest.GET(url).basicAuth(username, token), Argument.of(List, BintrayPackageSimple))
def response = client.exchange(HttpRequest.GET(url).basicAuth(username, token), Argument.of(List, BintrayPackageSimple))

log.trace("fetched {}", url)
List<BintrayPackageSimple> bintrayPackageList = response?.body()
Expand All @@ -84,8 +82,7 @@ class BintrayService implements GrailsConfigurationAware {
total: totalHeader(response.headers),
bintrayPackageList: bintrayPackageList)
} catch(HttpClientResponseException e) {
log.warn 'Response {}. Could not fetch bintray packages at {}', response.status.code, startPos

log.warn 'Response {}. Could not fetch bintray packages at {}', e.status.code, startPos
}
}

Expand Down
5 changes: 2 additions & 3 deletions grails-app/services/com/github/GithubService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,13 @@ class GithubService implements GrailsConfigurationAware {
return null
}
final String url = "/repos/${ownerAndRepo}".toString()
HttpResponse<GithubRepository> response = null
try {
response = client.exchange(HttpRequest.GET(url).basicAuth(username, token)
HttpResponse<GithubRepository> response = client.exchange(HttpRequest.GET(url).basicAuth(username, token)
.header("User-Agent", userAgent), GithubRepository)
log.trace("fetched {} github repository", ownerAndRepo)
return response.body()
} catch(HttpClientResponseException e) {
log.warn 'Response {}. Could not fetch github repository at {}', response?.status?.code, vcsUrl
log.warn 'Response {}. Could not fetch github repository at {}', e.status.code, vcsUrl
}
null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class GrailsPluginsService implements GrailsConfigurationAware {
.forEach({ plugin -> process(plugin) })
}
} catch (HttpClientResponseException e) {
log.warn 'Response {}. Could not fetch Grails plugin metadata from Gituhb with error {}', response.status.code, e.message
log.warn 'Response {}. Could not fetch Grails plugin metadata from Gituhb with error {}', e.status.code, e.message
}
}

Expand Down

0 comments on commit a4c022a

Please sign in to comment.