I have an ExceptionMapper
which is part of a generic common library:
@Provider
public class GenericExceptionMapper implements ExceptionMapper<GenericException> {
...
}
Now, in my specific project, I have my own ExceptionMapper
:
@Provider
public class SomeAdHocExceptionMapper implements ExceptionMapper<SomeAdHocException> {
...
}
I would like to convert the SomeAdHocException
to GenericException
and let GenericExceptionMapper
be responsible for further processing. I tried the following two options, but both are not working:
[1] throw GenericException
in SomeAdHocExceptionMapper
:
@Provider
public class SomeAdHocExceptionMapper implements ExceptionMapper<SomeAdHocException> {
public Response toResponse(SomeAdHocException e) {
throw new GenericException(e);
}
}
[2] inject GenericExceptionMapper
into SomeAdHocExceptionMapper
:
@Provider
public class SomeAdHocExceptionMapper implements ExceptionMapper<SomeAdHocException> {
@Inject
private GenericExceptionMapper mapper;
public Response toResponse(SomeAdHocException e) {
return mapper.toResponse(new GenericException(e));
}
}
Both options are giving dependency excpetions.
How do I solve this?