All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.phillipkruger.apiee.providers.NonUniqueResultExceptionMapper Maven / Gradle / Ivy

There is a newer version: 2.0.1
Show newest version
package com.github.phillipkruger.apiee.providers;

import javax.persistence.NonUniqueResultException;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;

/**
 * Translate Java non unique exceptions to HTTP response
 * @author Phillip Kruger ([email protected])
 */
@Provider
public class NonUniqueResultExceptionMapper implements ExceptionMapper {
    
    @Override
    @Produces(MediaType.APPLICATION_JSON)
    public Response toResponse(NonUniqueResultException nonUniqueResultException) {
        return Response.status(Response.Status.CONFLICT).header(REASON,nonUniqueResultException.getMessage()).build();
    }
    
    private static final String REASON = "reason";
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy