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

com.github.phillipkruger.microprofileextentions.config.NoSuchElementMapper Maven / Gradle / Ivy

There is a newer version: 1.0.8
Show newest version
package com.github.phillipkruger.microprofileextentions.config;

import java.util.NoSuchElementException;
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;
/**
 * Map a NoSuchElement to a Not Found
 * @author Phillip Kruger ([email protected])
 */
@Provider
public class NoSuchElementMapper implements ExceptionMapper{
    
    private static final String REASON = "Reason";

    @Override
    @Produces(MediaType.APPLICATION_JSON)
    public Response toResponse(NoSuchElementException noSuchElementException) {
        return Response.status(Response.Status.NOT_FOUND).header(REASON,noSuchElementException.getMessage()).build();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy