@Override
  public void doFilter(HttpRequest request, HttpResponse response, FilterChain chain) {
    IdentityProvider provider = resolveProviderOrHandleResponse(request, response, INIT_CONTEXT);
    if (provider != null) {
      handleProvider(request, response, provider);
    }
  }
@Test
  public void redirect_when_failing_because_of_Exception() throws Exception {
    IdentityProvider identityProvider = new FailWithIllegalStateException("failing");
    when(request.getRequestURI()).thenReturn("/sessions/init/" + identityProvider.getKey());
    identityProviderRepository.addIdentityProvider(identityProvider);

    underTest.doFilter(request, response, chain);

    verify(response).sendRedirect("/sessions/unauthorized");
    assertThat(logTester.logs(Level.WARN)).containsExactlyInAnyOrder("Fail to initialize authentication with provider 'failing'");
    verifyDeleteAuthCookie();
  }