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

io.quarkus.resteasy.runtime.CompositeExceptionMapper Maven / Gradle / Ivy

There is a newer version: 3.17.0
Show newest version
package io.quarkus.resteasy.runtime;

import jakarta.ws.rs.InternalServerErrorException;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider;
import jakarta.ws.rs.ext.Providers;

import io.smallrye.mutiny.CompositeException;

@Provider
public class CompositeExceptionMapper implements ExceptionMapper {

    @Context
    Providers p;

    @SuppressWarnings("unchecked")
    @Override
    public Response toResponse(CompositeException ex) {
        Throwable t = ex.getCauses().stream().filter(s -> s != null).findFirst()
                .orElseThrow(() -> new InternalServerErrorException());

        ExceptionMapper mapper = (ExceptionMapper) p.getExceptionMapper(t.getClass());
        if (mapper == null) {
            throw new InternalServerErrorException();
        }
        return mapper.toResponse(t);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy