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

com.bazaarvoice.ostrich.examples.dictionary.service.IllegalArgumentExceptionMapper Maven / Gradle / Ivy

The newest version!
package com.bazaarvoice.ostrich.examples.dictionary.service;

import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
import java.util.Optional;

@Provider
public class IllegalArgumentExceptionMapper implements ExceptionMapper {
    @Override
    public Response toResponse(IllegalArgumentException e) {
        return Response.status(Response.Status.BAD_REQUEST)
                .header("X-BV-Exception", e.getClass().getName())
                .entity(Optional.ofNullable(e.getMessage()).orElse("Invalid argument."))
                .build();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy