KEYCLOAK-1360 ModelExceptionMapper logges the exception

This commit is contained in:
mposolda 2015-05-28 19:19:30 +02:00
parent e1adceeb85
commit bcd607a1ee

View file

@ -4,6 +4,8 @@ import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper; import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider; import javax.ws.rs.ext.Provider;
import org.jboss.logging.Logger;
import org.keycloak.messages.MessagesProvider; import org.keycloak.messages.MessagesProvider;
import org.keycloak.models.KeycloakSession; import org.keycloak.models.KeycloakSession;
import org.keycloak.models.ModelException; import org.keycloak.models.ModelException;
@ -15,6 +17,8 @@ import org.keycloak.services.ErrorResponse;
@Provider @Provider
public class ModelExceptionMapper implements ExceptionMapper<ModelException> { public class ModelExceptionMapper implements ExceptionMapper<ModelException> {
private static final Logger logger = Logger.getLogger(ModelExceptionMapper.class);
@Context @Context
private KeycloakSession session; private KeycloakSession session;
@ -22,6 +26,8 @@ public class ModelExceptionMapper implements ExceptionMapper<ModelException> {
public Response toResponse(ModelException ex) { public Response toResponse(ModelException ex) {
String message = session.getProvider(MessagesProvider.class, "admin") String message = session.getProvider(MessagesProvider.class, "admin")
.getMessage(ex.getMessage(), ex.getParameters()); .getMessage(ex.getMessage(), ex.getParameters());
logger.error(message, ex);
return ErrorResponse.error(message, Response.Status.BAD_REQUEST); return ErrorResponse.error(message, Response.Status.BAD_REQUEST);
} }
} }