io.quarkus.resteasy.runtime.CompositeExceptionMapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of quarkus-resteasy Show documentation
Show all versions of quarkus-resteasy Show documentation
REST endpoint framework implementing JAX-RS and more
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);
}
}