I have a reactive springboot application, in it an aspect
@Before("approveRejectPointcut()")
public void logAfterReturning(JoinPoint joinPoint) {
Status newStatus = AspectUtils.returnFirstParameterOfTypeOrFail(allParameters, Status.class, "approveRejectPointcut");
String comments = AspectUtils.returnFirstParameterOfTypeOrFail(allParameters, String.class, "approveRejectPointcut");
Mono<Object> someObjectOrException = someService.updateApplicationStatus(appId, newStatus, comments);
someObjectOrException
.subscribe(i->log.info(i),
error->{
log.info("we have some ex: "+error.getMessage());
throw new RuntimeException("PLEASE LORD: "+error.getMessage());
});
}
What happens here, the updateApplicationStatus() from some service throws at some point a Business exception(which is good), in this aspect I print the exception message, which is also good. However, when i try to throw a business exception (a RuntimeException at it's base) .. i can see this exception in the console, however.. it does not reach the client. I suspect it is being thrown on a different thread. Any clues ?
In the end, changed the aspect to @Around
this way in case all goes well in the service -> we carry on with the execution, otherwise, we throw our business exception with the exception message from the service. Perhaps that map() should be replaced with some other operator accepting a funtion.. :)