I have a method handleException that return a ResponseEntity :
@ExceptionHandler({Exception.class})
public ResponseEntity handleException(Exception e) {
Map<String, String> data = new HashMap<>( );
List temp;
data.put( "message", e.getMessage() );
if (e instanceof MissingServletRequestParameterException) {
if ( e.getMessage().contains("countryName") )
{
temp = REP_MAP.get(Utility.HttpCode.REP_HTTP_CNABSENT);
} else{
temp = REP_MAP.get(Utility.HttpCode.REP_HTTP_DTABSENT);
}
data.clear();
data.put( "message", (String)temp.get(1));
return ResponseEntity.status((HttpStatus)temp.get(0)).body( data);
} else if (e instanceof CustomException) {
return ResponseEntity.status(((CustomException) e).getStatus()).body(data);
}
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(data);
}
and it was working fine before adding loggingInterceptor :
@Around("execution(* com.coviddata..*(..) )")
public Object logMethod(ProceedingJoinPoint joinPoint) throws Throwable {
Object temp = null;
String inputString = getInput(joinPoint);
logger.debug(inputString);
try{
temp = joinPoint.proceed();
}
catch (Exception e) {
logger.error( ERROR + " " + ((MethodSignature)joinPoint.getSignature()).getDeclaringTypeName() + " " + joinPoint.getSignature().getName() );
}
finally {
logger.debug( OUT + ((MethodSignature)joinPoint.getSignature()).getReturnType() );
return temp;
}
}
Now, i can log before and after of all methods. the problem is when an exception is thrown, this log method prevent my exception handler to be called and thus nothing is send to the user as ResponseENtity and even the joinPoin.proceed() return null.
I have tought to intercept all methods except handleException but I think this is not the problem. I think the solution of that. I want only to log when there is exception and return ResponseEntity.
Is there a way to exclude handleException method from being intercepted ?