// Path: src/main/java/org/letustakearest/application/service/ValidationException.java
// @Getter
// public class ValidationException extends RuntimeException {
// 
//     private final Set<ConstraintViolation<Object>> violations;
// 
//     private final String action;
// 
//     public ValidationException(Set<ConstraintViolation<Object>> violations, String action) {
//         this.violations = violations;
//         this.action = action;
//     }
// 
// }


import org.letustakearest.application.service.ValidationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
package org.letustakearest.infrastructure.jaxrs;



/**
 * @author volodymyr.tsukur
 */
@Provider
public class ValidationExceptionMapper implements ExceptionMapper<ValidationException> {

    @Context
    private UriInfo uriInfo;

    @Override
    public Response toResponse(final ValidationException exception) {
        final Error error = new Error();
        error.setType(exception.getClass().getSimpleName());
        error.setMessage(exception.getMessage());
        error.setAction(exception.getAction());
        error.setLink(uriInfo.getBaseUriBuilder().segment("error", exception.getAction()).build().toString());
        return Response.
                status(Response.Status.BAD_REQUEST).
// Path: src/main/java/org/letustakearest/application/service/ValidationException.java
// @Getter
// public class ValidationException extends RuntimeException {
// 
//     private final Set<ConstraintViolation<Object>> violations;
// 
//     private final String action;
// 
//     public ValidationException(Set<ConstraintViolation<Object>> violations, String action) {
//         this.violations = violations;
//         this.action = action;
//     }
// 
// }


// Path: src/main/java/org/letustakearest/infrastructure/jaxrs/ValidationExceptionMapper.java
import org.letustakearest.application.service.ValidationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;

package org.letustakearest.infrastructure.jaxrs;



/**
 * @author volodymyr.tsukur
 */
@Provider
public class ValidationExceptionMapper implements ExceptionMapper<ValidationException> {

    @Context
    private UriInfo uriInfo;

    @Override
    public Response toResponse(final ValidationException exception) {
        final Error error = new Error();
        error.setType(exception.getClass().getSimpleName());
        error.setMessage(exception.getMessage());
        error.setAction(exception.getAction());
        error.setLink(uriInfo.getBaseUriBuilder().segment("error", exception.getAction()).build().toString());
        return Response.
                status(Response.Status.BAD_REQUEST).
                entity(error).