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

no.nav.apiapp.rest.ReadExceptionHandler Maven / Gradle / Ivy

package no.nav.apiapp.rest;

import javax.ws.rs.WebApplicationException;
import javax.ws.rs.ext.ReaderInterceptor;
import javax.ws.rs.ext.ReaderInterceptorContext;
import java.io.IOException;

import static no.nav.apiapp.feil.FeilType.UGYLDIG_REQUEST;


public class ReadExceptionHandler implements ReaderInterceptor {

    private final ExceptionMapper exceptionMapper;

    public ReadExceptionHandler(ExceptionMapper exceptionMapper) {
        this.exceptionMapper = exceptionMapper;
    }

    @Override
    public Object aroundReadFrom(ReaderInterceptorContext context) throws IOException {
        try {
            return context.proceed();
        } catch (Throwable e) {
            throw new WebApplicationException(exceptionMapper.toResponse(e, UGYLDIG_REQUEST));
        }
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy