Skip to content

Commit

Permalink
Catch ApolloHttpException when fetching vulnerabilities
Browse files Browse the repository at this point in the history
We have experienced in production that the apollo client fails
to fetch vulnerabilities, which results in the application becoming
stagnant. In these cases, we simply want the application to continue,
hoping that vulnerabilities will be fetched successfully on the next
loop.
  • Loading branch information
hermanwh committed Sep 24, 2024
1 parent 2c333e6 commit a5efa30
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/main/kotlin/no/digipost/github/monitoring/GithubGraphql.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.apollographql.apollo3.ApolloCall
import com.apollographql.apollo3.ApolloClient
import com.apollographql.apollo3.api.ApolloResponse
import com.apollographql.apollo3.api.Optional
import com.apollographql.apollo3.exception.ApolloHttpException
import com.github.graphql.client.GetVulnerabilityAlertsForRepoQuery
import com.github.graphql.client.QueryRepositoriesQuery
import kotlinx.coroutines.channels.Channel
Expand Down Expand Up @@ -47,12 +48,16 @@ fun fetchAllReposWithVulnerabilities(apolloClient: ApolloClient, githubApiClient
repositories.add(r)

launch {
val vulnerabilities = getVulnerabilitiesForRepo(apolloClient, r.name)
if (vulnerabilities.isNotEmpty()) {
r.copy(vulnerabilities = vulnerabilities).let {
logger.info("{} sårbarheter i {}", vulnerabilities.size, r.name)
vulnRepositories[it.name] = vulnerabilities
try {
val vulnerabilities = getVulnerabilitiesForRepo(apolloClient, r.name)
if (vulnerabilities.isNotEmpty()) {
r.copy(vulnerabilities = vulnerabilities).let {
logger.info("{} sårbarheter i {}", vulnerabilities.size, r.name)
vulnRepositories[it.name] = vulnerabilities
}
}
} catch (e: ApolloHttpException) {
logger.warn("ApolloHttpException ved henting av sårbarheter for repo {}", r.name, e)
}
}

Expand Down

0 comments on commit a5efa30

Please sign in to comment.