com.quorum.tessera.enclave.rest.DefaultExceptionMapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of enclave-jaxrs Show documentation
Show all versions of enclave-jaxrs Show documentation
Tessera is a stateless Java system that is used to enable the encryption, decryption, and distribution of private transactions for Quorum.
package com.quorum.tessera.enclave.rest;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Provider
public class DefaultExceptionMapper implements ExceptionMapper {
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultExceptionMapper.class);
@Override
public Response toResponse(final Throwable ex) {
final Throwable rootCause = ExceptionUtils.getRootCause(ex);
final Throwable cause = (rootCause == null) ? ex : rootCause;
LOGGER.error("Error occurred: {}. Root cause: {}", ex.getMessage(), cause.getMessage());
LOGGER.debug(null, ex);
LOGGER.debug(null, cause);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
.entity(cause.getMessage())
.type(MediaType.TEXT_PLAIN)
.build();
}
}