Skip to content

Commit

Permalink
add a third argument catch
Browse files Browse the repository at this point in the history
  • Loading branch information
fzhao99 committed Jan 8, 2024
1 parent d1410d5 commit a501da6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@ public Health health() {
log.info("Okta status didn't return ACTIVE, instead returned " + oktaStatus);
return Health.down().build();
}

return Health.up().build();
} catch (IllegalArgumentException e) {
// reach into the ff repository returned a bad value
return Health.down().build();
} catch (JDBCConnectionException e) {
// db connection issue
return Health.down().build();
// Okta API call errored
} catch (ApiException e) {
// Okta API call errored
log.info(e.getMessage());
return Health.down().build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,22 @@ void health_succeedsWhenReposDoesntThrow() {
}

@Test
void health_failsWhenFeatureFlagRepoDoesntThrow() {
void health_failsWhenDBConnectionThrows() {
JDBCConnectionException dbConnectionException =
new JDBCConnectionException(
"connection issue", new SQLException("some reason", "some state"));
when(mockFeatureFlagRepo.findAll()).thenThrow(dbConnectionException);
assertThat(indicator.health()).isEqualTo(Health.down().build());
}

@Test
void health_failsWhenFeatureFlagRepoThrows() {
IllegalArgumentException dbConnectionException =
new IllegalArgumentException("some argument message");
when(mockFeatureFlagRepo.findAll()).thenThrow(dbConnectionException);
assertThat(indicator.health()).isEqualTo(Health.down().build());
}

@Test
void health_failsWhenOktaRepoDoesntReturnActive() {
when(mockOktaRepo.getApplicationStatusForHealthCheck()).thenReturn("INACTIVE");
Expand Down

0 comments on commit a501da6

Please sign in to comment.