Skip to content

Commit

Permalink
chore(jans-auth-server): avoid redirect exception logging on every au…
Browse files Browse the repository at this point in the history
…thn #2287 (#2328)

docs: no docs
#2287
  • Loading branch information
yuriyz committed Sep 8, 2022
1 parent 00f4f79 commit 5c752d1
Showing 1 changed file with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
package io.jans.as.server.exception;

import io.jans.as.server.model.exception.InvalidSessionStateException;
import jakarta.ws.rs.WebApplicationException;
import jakarta.ws.rs.core.Response;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -48,13 +50,8 @@ public void handle() throws FacesException {
final FacesContext fc = FacesContext.getCurrentInstance();
final ExternalContext externalContext = fc.getExternalContext();
try {
if (isInvalidSessionStateException(t)) {
log.error(t.getMessage(), t);
performRedirect(externalContext, "/error_session.htm");
} else {
log.error(t.getMessage(), t);
performRedirect(externalContext, "/error_service.htm");
}
logExceptionAsError(t);
performRedirect(externalContext, isInvalidSessionStateException(t) ? "/error_session.htm" : "/error_service.htm");
fc.renderResponse();
} finally {
i.remove();
Expand All @@ -63,6 +60,21 @@ public void handle() throws FacesException {
getWrapped().handle();
}

private void logExceptionAsError(Throwable t) {
if (!log.isErrorEnabled()) {
return;
}

if (t instanceof WebApplicationException) {
Response response = ((WebApplicationException) t).getResponse();
if (response != null && response.getStatus() == 302) {
return;
}
}

log.error(t.getMessage(), t);
}

private boolean isInvalidSessionStateException(Throwable t) {
return ExceptionUtils.getRootCause(t) instanceof InvalidSessionStateException;
}
Expand Down

0 comments on commit 5c752d1

Please sign in to comment.