katharsis-project / katharsis-framework

Katharsis adds powerful layer for RESTful endpoints providing implementenation of JSON:API standard
http://katharsis.io
Apache License 2.0
135 stars 65 forks source link

Unable to add ExceptionMappers with Katharsis-cdi #450

Open celdridge91190 opened 7 years ago

celdridge91190 commented 7 years ago

I'm trying to add a Custom ExceptionMapper using Katharsis-cdi. The mapper is unable to be found using CDIServiceDiscovery. After debugging, I found that the issue is matching on an interface that has a GenericType added. Weld CDI expects the mapper to contain an instance of TypeVariable. Please correct me if I'm missing something, but I've been unable to figure out a way to get this to work. Classes below

public class CliServiceException extends RuntimeException { private final String id; private final String title; private final int statusCode;

public CliServiceException(String id, String title, int statusCode, Throwable cause){
    this(id, title, statusCode);
    this.initCause(cause);
}

public CliServiceException(String id, String title, Throwable cause){
    this(id, title, HttpStatus.INTERNAL_SERVER_ERROR_500, cause);
}

public CliServiceException(String id, String title, int statusCode){
    this.id = id;
    this.title = title;
    this.statusCode = statusCode;
}

public CliServiceException(String id, String title){
    this(id, title, HttpStatus.INTERNAL_SERVER_ERROR_500);
}

public String getId() {
    return id;
}

public String getTitle() {
    return title;
}

public int getStatusCode() {
    return statusCode;
}

}`

public class CliServiceExceptionMapper implements JsonApiExceptionMapper {

public CliServiceExceptionMapper() {

}

@Override
public ErrorResponse toErrorResponse(CliServiceException exception) {
    return null;
}

}

Problem code in Weld CDI

public static boolean isArrayOfUnboundedTypeVariablesOrObjects(Type[] types) {
    for (Type type : types) {
        if (Object.class.equals(type)) {
            continue;
        }
        if (type instanceof TypeVariable<?>) {
            Type[] bounds = ((TypeVariable<?>) type).getBounds();
            if (bounds == null || bounds.length == 0 || (bounds.length == 1 && Object.class.equals(bounds[0]))) {
                continue;
            }
        }
        return false;
    }
    return true;
}
celdridge91190 commented 7 years ago

Not sure if it helps but I noticed the build in Exception mappers are not getting picked up either (such as io.katharsis.core.internal.exception.KatharsisExceptionMapper