package ru.fitgraph.rest.exceptions;
import org.apache.log4j.Logger;
import ru.fitgraph.rest.elements.ErrorResponse;

import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;

/**
 * Mapper for catch all internal exceptions. All uncatched exception will be processed by this
 * class.
 *
 * @author Morgen Matvey
 */
@Provider
public class InternalExceptionMapper implements ExceptionMapper<Throwable> {

    private final static Logger logger = Logger.getLogger(InternalExceptionMapper.class);

    @Override
    public Response toResponse(Throwable exception) {
        logger.error("There are unresolved exception!", exception);
        ErrorResponse response =
                new ErrorResponse("InternalServerErrorException", "Internal problem on server, try later.");
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(response).build();
    }
}

Add mapper for internal server exceptions.
Add mapper for internal server exceptions.
